Skip to content

Commit

Permalink
forEach() requires 'this' argument (#1356)
Browse files Browse the repository at this point in the history
* forEach() requires 'this' argument

Otherwise, this is evaluated to undefined, which causes cryptic errors like:

`Cannot read property 'method' of undefined`

instead of:

`writeFileSync received wrong arguments(...)`

* Repairs one test to allow it to detect the bug.
  • Loading branch information
hrimhari authored and mantoni committed May 3, 2017
1 parent 4ef01ca commit af735ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sinon/mock-expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var mockExpectation = {
mockExpectation.fail(this.method + " received wrong arguments " + format(args) +
", expected " + format(expectedArguments));
}
});
}, this);
},

allowsCall: function allowsCall(thisValue, args) {
Expand Down
13 changes: 12 additions & 1 deletion test/mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,17 @@ describe("sinonMock", function () {
});

describe(".withArgs", function () {
var expectedException = function (name) {
return {
test: function (actual) {
return actual.name === name;
},
toString: function () {
return name;
}
};
};

it("returns expectation for chaining", function () {
assert.same(this.expectation.withArgs(1), this.expectation);
});
Expand Down Expand Up @@ -510,7 +521,7 @@ describe("sinonMock", function () {

assert.exception(function () {
expectation(2, 2, 3);
}, "ExpectationError");
}, expectedException("ExpectationError"));
});

it("allows excessive args", function () {
Expand Down

0 comments on commit af735ad

Please sign in to comment.