Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not matcher and calling function multiple times #122

Closed
adamniedzielski opened this issue Jul 26, 2016 · 2 comments
Closed

not matcher and calling function multiple times #122

adamniedzielski opened this issue Jul 26, 2016 · 2 comments

Comments

@adamniedzielski
Copy link

Thank you for the amazing library - I'm a happy user! I found one issue with how the "not" matcher behaves when the function is called multiple times. Please, take a look:

let roll = td.function();
roll(1);
td.verify(roll(td.matchers.not(1)));

This works as expected - the test fails with:

Unsatisfied verification on test double.

              Wanted:
                - called with `(not(1))`.

              But was actually called:
                - called with `(1)`.

However this one does not fail the test:

let roll = td.function();
roll(4);
roll(1);
td.verify(roll(td.matchers.not(1)));

I guess that the problem here is that one function call ("4") satisfies the matcher. I wonder whether the "not" matcher should mean "none of the calls equal" or "not every call equals". What do you think?

@searls
Copy link
Member

searls commented Jul 26, 2016

Yeah, you diagnosed the issue you ran into here. My recommendation (since it should be unusual that a collaboration test should intentionally make a test double blow up) would be to treat the explosion as a stubbing and not a verification.

Reason being: verifying something did not happen isn't much of a specification at all (surely there are millions of things your subject under test doesn't do, but they don't all warrant an assertion)

Try this instead:

let roll = td.function();
td.when(roll(1)).thenThrow(new Error('woah do not roll a 1'))

roll(1);

@searls searls closed this as completed Jul 26, 2016
@adamniedzielski
Copy link
Author

@searls Your reasoning makes sense. Thank you very much for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants