Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Enable a name to be assigned to a mock #22

kgilpin opened this Issue · 3 comments

3 participants


Currently the only descriptive name on a mock is the function being mocked.

However if two mocks are both mocking the same function name (e.g. 'error') there isn't a way to tell from the assert error message which 'error' function was not called.


Hmm, Interesting.
How do we provided the description.
I've given some possible ways. Add some ways you prefer.

nodemock.mock('foo', 'this is the discription').return(100);
nodemock.of('testing the description').mock('foo').returns(130).

I am coming from Ruby where an option hash is common; so another possibility is:

nodemock.mock({name:"my name"})`

nodemock.mock("foo", {name:"my name"})

which leaves the possibility of other options as well. But I also like your chaining (second one). The first one I think is not workable because:


is ambiguous whether 'description' is the description or the method to mock.

@realistschuckle realistschuckle referenced this issue in realistschuckle/nodemock

Enable a name to be assigned to a mock #6


@kgilpin If you still want this feature, you can find it in the "newer" repo over at I shimmed in a new method that does not break the current signature of the library. It allows you to do this:

var nm = require('nodemock')
  , mock = nm.named('myFabulousMock').mock('someMethod').return(100)

mock.assert(); // Prints out that myFabulousMock.someMethod() did not get called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.