toHaveBeenCalled
:如果调用了spy,则 toHaveBeenCalled 将通过调用。
toHaveBeenCalledWith
: 如果参数列表与spy调用时的参数相匹配,则返回true。
toHaveBeenCalledTimes
:如果spy被调用了指定的次数,则 toHaveBeenCalledTimes 将通过调用。
// The example comes from Jasmine official
describe("A spy", function() {
var foo, bar = null;
beforeEach(function() {
foo = {
setBar: function(value) {
bar = value;
}
};
spyOn(foo, 'setBar');
foo.setBar(123);
foo.setBar(456, 'another param');
});
it("tracks that the spy was called", function() {
expect(foo.setBar).toHaveBeenCalled();
});
it("tracks that the spy was called x times", function()