javascript - How to have different return values for multiple calls on a Jasmine spy -
say i'm spying on method this:
spyon(util, "foo").andreturn(true);
the function under test calls util.foo
multiple times.
is possible have spy homecoming true
first time it's called, homecoming false
sec time? or there different way go this?
you can utilize spy.and.returnvalues (as jasmine 2.4).
for example
class="snippet-code-js lang-js prettyprint-override">describe("a spy, when configured false series of homecoming values", function() { beforeeach(function() { spyon(util, "foo").and.returnvalues(true, false); }); it("when called multiple times returns requested values in order", function() { expect(util.foo()).tobetruthy(); expect(util.foo()).tobefalsy(); expect(util.foo()).tobeundefined(); }); });
javascript unit-testing jasmine
No comments:
Post a Comment