jeudi 22 janvier 2015

Unit testing the effects on an AngularJS $rootScope.$emit

I'm writing an AngularJS unit test that emits and event and then calls a service to see if the event was processed correctly.



$rootScope.$emit('MY_EVENT');
expect(MyService.foo).toEqual('bar');


My service implements the event listener in the conventional manner:



// function called asynchronously?
$rootScope.$on('MY_EVENT', function(event, result) {
//do something synchronous
});


Though my test currently passes I'm concerned that my event listener is probably being processed asynchronously.


My question is, is calling $rootScope.$digest() before my expectation enough to insure that all the event listeners have been called and returned?


Aucun commentaire:

Enregistrer un commentaire