Skip to content

Commit

Permalink
Add test for issue sinonjs#1274
Browse files Browse the repository at this point in the history
  • Loading branch information
takasmiley committed Mar 2, 2017
1 parent feced07 commit 2e9bb09
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/issues/issues-test.js
Expand Up @@ -200,4 +200,49 @@ describe("issues", function () {
assert(firstFake !== secondFake);
});
});

describe("#1274 - spy.withArgs(args...).callCount is incorrect", function () {
it("case1: should count accurately", function () {
var obj = {
f: function () {}
};

// case1: withArgs(1) => withArgs(1, 1)
var spy = sinon.spy(obj, "f");
assert.equals(spy.callCount, 0);
assert.equals(spy.withArgs(1).callCount, 0);
assert.equals(spy.withArgs(1, 1).callCount, 0);

obj.f();
obj.f(1);
obj.f(1, 1);
obj.f(1, 2);

assert.equals(spy.callCount, 4);
assert.equals(spy.withArgs(1).callCount, 3);
assert.equals(spy.withArgs(1, 1).callCount, 1);
assert.equals(spy.withArgs(1, 2).callCount, 1);
});
it("case2: should count accurately", function () {
var obj = {
f: function () {}
};

// case2: withArgs(1, 1) => withArgs(1)
var spy = sinon.spy(obj, "f");
assert.equals(spy.callCount, 0);
assert.equals(spy.withArgs(1, 1).callCount, 0);
assert.equals(spy.withArgs(1).callCount, 0);

obj.f();
obj.f(1);
obj.f(1, 1);
obj.f(1, 2);

assert.equals(spy.callCount, 4);
assert.equals(spy.withArgs(1).callCount, 3);
assert.equals(spy.withArgs(1, 1).callCount, 1);
assert.equals(spy.withArgs(1, 2).callCount, 1);
});
});
});

0 comments on commit 2e9bb09

Please sign in to comment.