Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Enable a name to be assigned to a mock #22

Open
kgilpin opened this Issue · 3 comments

3 participants

@kgilpin

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.

@arunoda
Owner

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

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
Closed

Enable a name to be assigned to a mock #6

@realistschuckle

@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
Something went wrong with that request. Please try again.