Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Enable a name to be assigned to a mock #22

Open
kgilpin opened this Issue Apr 13, 2012 · 3 comments

Comments

Projects
None yet
3 participants

kgilpin commented Apr 13, 2012

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.

Owner

arunoda commented Apr 14, 2012

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).

kgilpin commented Apr 14, 2012

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:

nodemock.mock('description')

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

@realistschuckle realistschuckle referenced this issue in realistschuckle/nodemock Jan 29, 2014

Closed

Enable a name to be assigned to a mock #6

Contributor

realistschuckle commented Jan 29, 2014

@kgilpin If you still want this feature, you can find it in the "newer" repo over at https://github.com/realistschuckle/nodemock. 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