Skip to content

Commit

Permalink
Merge pull request #1489 from Rowno/named-anonymous-mocks
Browse files Browse the repository at this point in the history
Allow anonymous mock functions to be named
  • Loading branch information
mroderick committed Jul 26, 2017
2 parents c9a35ef + 837ec0c commit 57bb8b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/release-source/release/mocks.md
Expand Up @@ -103,7 +103,7 @@ Creates an expectation without a mock object, basically an anonymous mock functi
Method name is optional and is used in exception messages to make them more readable.


#### `var expectation = sinon.mock();`
#### `var expectation = sinon.mock([methodName]);`

The same as the above.

Expand Down
4 changes: 2 additions & 2 deletions lib/sinon/mock.js
Expand Up @@ -10,8 +10,8 @@ var wrapMethod = require("./util/core/wrap-method");
var push = Array.prototype.push;

function mock(object) {
if (!object) {
return mockExpectation.create("Anonymous mock");
if (!object || typeof object === "string") {
return mockExpectation.create(object ? object : "Anonymous mock");
}

return mock.create(object);
Expand Down
10 changes: 10 additions & 0 deletions test/mock-test.js
Expand Up @@ -10,6 +10,16 @@ var assert = referee.assert;
var refute = referee.refute;

describe("sinonMock", function () {
it("creates anonymous mock functions", function () {
var expectation = sinonMock();
assert.equals(expectation.method, "Anonymous mock");
});

it("creates named anonymous mock functions", function () {
var expectation = sinonMock("functionName");
assert.equals(expectation.method, "functionName");
});

describe(".create", function () {
it("returns function with expects method", function () {
var mock = sinonMock.create({});
Expand Down

0 comments on commit 57bb8b3

Please sign in to comment.