-
Notifications
You must be signed in to change notification settings - Fork 107
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
[feature-request] Clean way to test a specific spy call #69
Comments
The correct approach here is to just create a separate test per call, or to use assertion message overrides. Anyway, Sinon–Chai simple provides what Sinon provides, and since Sinon does not provide this sort of thing, I don't plan to add it to Sinon–Chai. |
Actually, People on my project were doing things like:
which did not give nice test failure messages (something like 'expected false to be true'). Doing this instead:
is nicer but could be improved upon. And btw. |
Oh! Well, those still work with Sinon–Chai chai. expect(spy.firstCall).to.be.calledWithExactly(...) |
Yeah, they work, but their test output is less than optimal. 😄 As described in my original issue description, when they fail, they output data passed in to all the calls, and there is no mention anywhere of what call the failure is being reported for. For example this is based on an actual failure like that in one of our test suites (specific data & file names have been replaced so I don't have to go through the trouble of discovering what may or may not be publicly shareable):
As you can see, the test failure output complains about The problem is that the actual test code was specifically testing the second call, and not any of them, and that is important information that would be very helpful if displayed in the test failure output. The perfect test failure output for this case would be something like:
|
Hmm. And when you use Sinon directly, its assertion messages specify which call? |
Yup, just tried it using Sinon directly, and it does not specify the exact call index, but it does list only the one call being tested, so in the example used before it would output:
which is good, as the reader now knows the exact call parameters being compared. |
I just ran into a similar test scenario where the call is internally recursive so being able to assert/expect on separate calls would have been handy. Is this on the roadmap? |
There is no "roadmap", but this project does accept pull requests. |
We can use a construct like:
and that works, but when that test fails, there is no mention of the fact that it was related to the second call in the test output. In fact, it displays the expected parameters and all the call information, which can get pretty confusing assuming that the expected call was made, just not as the second one.
It would be nice if
sinon-chai
gave us a way to cleanly test a specific spy call and report such failures in a way that would not require opening the test code to see what it was that was actually being expected.One idea might be to support something like this:
but possibly a solution can be found that would be more like a readable English sentence.
Many thanks!
The text was updated successfully, but these errors were encountered: