Reset call on Jasmine spy does not return
Another way to write it:
const spy = spyOn(foo, 'bar');
expect(spy).toHaveBeenCalled();
spy.calls.reset();
The syntax for Jasmine 2 is different than 1.3 with respect to spy functions. See Jasmine docs here.
Specifically you reset a spy with spy.calls.reset();
This is how the test should look like:
// Source
var objectUnderTest = {
someFunction: function (cb) {
var promise = new Promise(function (resolve, reject) {
if (true) {
cb();
resolve();
} else {
reject(new Error("something bad happened"));
}
});
return promise;
}
}
// Test
describe('foo', function () {
it('tests', function (done) {
var spy = jasmine.createSpy('mySpy');
objectUnderTest.someFunction(spy).then(function () {
expect(spy).toHaveBeenCalled();
done();
});
});
it('tests deeper', function (done) {
var spy = jasmine.createSpy('mySpy');
objectUnderTest.someFunction(spy).then(function () {
expect(spy).toHaveBeenCalled();
spy.calls.reset();
return objectUnderTest.someFunction(spy);
}).then(function () {
expect(spy).toHaveBeenCalled();
expect(spy.calls.count()).toBe(1);
done();
});
});
});
See fiddle here