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 Feb 28, 2017
1 parent feced07 commit b96397e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/issues/issues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,45 @@ describe("issues", function () {
assert(firstFake !== secondFake);
});
});

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

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

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

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

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

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

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

0 comments on commit b96397e

Please sign in to comment.