Hi I have written a fairly trivial decorator around the '$exceptionHandler' 
service so I can post any failures to a http endpoint. This seems to be 
work fine and I'm pleased with its simplicity.

I am however having trouble testing this aspect of my application in 
jasmine. I have tried loading my whole app in the test i.e. 'myApp' but 
this to just hang the jasmine runner and crash PhantomJS & Chrome when 
running. 

Any ideas how I can test this code, ideally in isolation?

Thanks for any tips,

James

The provider:

###
 * Decorate the `$exceptionHandler` providing functionality for logging
 ###
app.config(($provide) ->
    $provide.decorator("$exceptionHandler", ($delegate, 
ErrorLoggingService) ->
        (exception, cause) ->

            # Delegate on the original `$exceptionHandler` i.e. $log.error()
            $delegate(exception, cause)

            # Record the error server side
            ErrorLoggingService.logError(exception, cause)
    )
)


The test so far:

describe('$exceptionHandler', function() {

    beforeEach(module('myApp.exceptionHandler'));

    function TestOnlyCtrl($exceptionHandler) {
        $exceptionHandler("Some Random Error")
    }

    // Run test
    describe('$exceptionHandler delegation', function(){

        var $log, $httpBackend, ErrorLoggingService;

        var exception = {
            message: "Error Message",
            stack: "Error Stack"
        };
        var cause = "Some Cause";

        beforeEach(module(function($exceptionHandlerProvider) {
            $exceptionHandlerProvider.mode("log");
        }));

        beforeEach(inject(function($injector, $controller) {
            $log = $injector.get('$log');
            $httpBackend = $injector.get('$httpBackend');
            $exceptionHandler = $injector.get('$exceptionHandler');

            $controller(TestOnlyCtrl);

            ErrorLoggingService = $injector.get('ErrorLoggingService');
        }));

        afterEach(function() {
             $httpBackend.verifyNoOutstandingExpectation();
             $httpBackend.verifyNoOutstandingRequest();
             $log.reset();
        });

        it('Should record and delegate on to ErrorLoggingService', 
function() {

            // I Should be able to do my asserts on the delegated service 
here?
            expect($exceptionHandler.errors[0]).toEqual("Some Random 
Error");
            
        });
    });
});

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to