Ответ 1
Синтаксис для Жасмина 2 отличается от 1,3 по отношению к функциям шпиона. См. Jasmine docs here.
В частности, вы reset шпион с spy.calls.reset();
Вот как выглядит тест:
// 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();
});
});
});
Смотрите скрипку здесь