I've come across a case where I simply can't make the test passed.
Here is the test:
it('should accept an fucntion run it immediately', inject(function($rootScope, ready) {
var spy = jasmine.createSpy('ready').andCallFake(function(){
console.log("I'm ready");
});
ready.done(spy);
expect(spy).toHaveBeenCalled();
}));
Here is code:
angular.module('myApp').factory('ready', function($q, _, $rootScope){
var defer = $q.defer();
//in real case it's actually calling 3rd party code, so no $timeout
_.defer(function(){
$rootScope.$apply(function(){
defer.resolve();
});
});
return {
done: function(fn){
defer.promise.then(fn);
}
};
});
The log of I'm ready
did appeared but the test still failed. So I think its just the problem of handling async flow in jasmine
. But I can't think of to test it using jasmine's runs
and waitsFor
.