I'm using a Jasmine (2.2.0) spy to see if a certain callback is called.
Test code:
it('tests', function(done) {
var spy = jasmine.createSpy('mySpy');
objectUnderTest.someFunction(spy).then(function() {
expect(spy).toHaveBeenCalled();
done();
});
});
This works as expected. But now, I'm adding a second level:
it('tests deeper', function(done) {
var spy = jasmine.createSpy('mySpy');
objectUnderTest.someFunction(spy).then(function() {
expect(spy).toHaveBeenCalled();
spy.reset();
return objectUnderTest.someFunction(spy);
}).then(function() {
expect(spy.toHaveBeenCalled());
expect(spy.callCount).toBe(1);
done();
});
});
This test never returns, because apparently the done
callback is never called. If I remove the line spy.reset()
, the test does finish, but obviously fails on the last expectation. However, the callCount
field seems to be undefined
, rather than 2
.
.catch(done)
to the end of the chain, same problem occurs. So @Daniel, if it's throwing I can't detect it. – Bluebirdtry/catch
does reveal the exception:'undefined' is not a function (evaluating 'spy.reset()')
. I'm not sure why this isn't correctly handled by Q / Jasmine. I'm also not sure why my spy is missing several properties it normally should have. – Bluebird