Skip to content

Commit

Permalink
Cleanup a few test codes
Browse files Browse the repository at this point in the history
  • Loading branch information
takasmiley committed Jul 3, 2017
1 parent 1ff2b9b commit 40efa6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions test/spy-test.js
Expand Up @@ -327,40 +327,37 @@ describe("spy", function () {
});

it("should work with combination of withArgs arguments and order of calling withArgs", function () {
var assertSpy = function (spy) {
function assertSpy(spy) {
// assert callCount
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);

// assert call
assert.equals(spy.getCall(0).args[0], undefined);
refute.defined(spy.getCall(0).args[0]);
assert.equals(spy.getCall(1).args[0], 1);
assert.equals(spy.getCall(1).args[1], undefined);
refute.defined(spy.getCall(1).args[1]);
assert.equals(spy.getCall(2).args[0], 1);
assert.equals(spy.getCall(2).args[1], 1);
assert.equals(spy.getCall(2).args[2], undefined);
refute.defined(spy.getCall(2).args[2]);
assert.equals(spy.getCall(3).args[0], 1);
assert.equals(spy.getCall(3).args[1], 2);
assert.equals(spy.getCall(3).args[2], undefined);
refute.defined(spy.getCall(3).args[2]);
["args", "callCount", "callId"].forEach(function (propName) {
assert.equals(spy.withArgs(1).getCall(0)[propName],
spy.getCall(1)[propName]);
assert.equals(spy.withArgs(1).getCall(1)[propName],
spy.getCall(2)[propName]);
assert.equals(spy.withArgs(1).getCall(2)[propName],
spy.getCall(3)[propName]);
assert.equals(spy.withArgs(1).getCall(3),
null);
assert.isNull(spy.withArgs(1).getCall(3));
assert.equals(spy.withArgs(1, 1).getCall(0)[propName],
spy.getCall(2)[propName]);
assert.equals(spy.withArgs(1, 1).getCall(1),
null);
assert.isNull(spy.withArgs(1, 1).getCall(1));
assert.equals(spy.withArgs(1, 2).getCall(0)[propName],
spy.getCall(3)[propName]);
assert.equals(spy.withArgs(1, 2).getCall(1),
null);
assert.isNull(spy.withArgs(1, 2).getCall(1));
});

// assert firstCall, secondCall, thirdCall, and lastCall
Expand All @@ -373,14 +370,14 @@ describe("spy", function () {
assert.equals(spy.withArgs(1).thirdCall.callId, spy.withArgs(1).getCall(2).callId);
assert.equals(spy.withArgs(1).lastCall.callId, spy.withArgs(1).getCall(2).callId);
assert.equals(spy.withArgs(1, 1).firstCall.callId, spy.withArgs(1, 1).getCall(0).callId);
assert.equals(spy.withArgs(1, 1).secondCall, null);
assert.equals(spy.withArgs(1, 1).thirdCall, null);
assert.isNull(spy.withArgs(1, 1).secondCall);
assert.isNull(spy.withArgs(1, 1).thirdCall);
assert.equals(spy.withArgs(1, 1).lastCall.callId, spy.withArgs(1, 1).getCall(0).callId);
assert.equals(spy.withArgs(1, 2).firstCall.callId, spy.withArgs(1, 2).getCall(0).callId);
assert.equals(spy.withArgs(1, 2).secondCall, null);
assert.equals(spy.withArgs(1, 2).thirdCall, null);
assert.isNull(spy.withArgs(1, 2).secondCall);
assert.isNull(spy.withArgs(1, 2).thirdCall);
assert.equals(spy.withArgs(1, 2).lastCall.callId, spy.withArgs(1, 2).getCall(0).callId);
};
}

var object = {
f1: function () {},
Expand Down
2 changes: 1 addition & 1 deletion test/stub-test.js
Expand Up @@ -121,7 +121,7 @@ describe("stub", function () {
stub.withArgs(1).returns(42);
stub(1);

assert.isObject(stub.withArgs(1).firstCall);
refute.isNull(stub.withArgs(1).firstCall);
});

describe(".returns", function () {
Expand Down

0 comments on commit 40efa6f

Please sign in to comment.