Skip to content Skip to sidebar Skip to footer

Test An Asynchronous Function Not Within A Service

If I have a directive that takes a function from the scope, and that function is asynchronous how could I test that? For example angular.module('myApp').factory('AsyncService',() =

Solution 1:

The service should be stubbed:

beforeEach(() => {
  module('myApp', { AsyncService: { async: jasmine.createSpy() } });
})

Then the method can be mocked to return a promise before directive compilation:

AsyncService.async.and.returnValue($q.resolve(...));

Post a Comment for "Test An Asynchronous Function Not Within A Service"