Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Mock $httpBackend.flush() method never return/exit if custom $exceptionHandler use $http #11863

Open
@fantarama

Description

@fantarama

If a module customize $exceptionHandler like this:

angular.module("myModule", [])
    .factory("$exceptionHandler", ["$http", function ($http) {
        return function (exception, cause) {
            $http.post("myserver/logger/service", exception);
        };
    }]);

With a generic controller's unit test like this:

it('Should call my service', inject(function($httpBackend, $controller) {
    $httpBackend.expectGET('myserver/resources/myresource');
    var ctrl = $controller('mycontroller');

    $httpBackend.flush();

    // ISSUE: code never called if $exceptionHandler POST isn't mocked

    expect(ctrl.someProperty).toBe('somevalue');

}));

The test excecution enter the flush method and never exit causing the browser to halt on a javascript function and Karma stop responding (I need to kill the process!)

If I mock the $http.post("myserver/logger/service", exception) then work as expected.

The main problem is that the code halt on flush method without any visible exception or error, and since logger and exception handling are aspect not focused on controller testing to find out the fail reason is very hard.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions