-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Add expectation diff logs #1203
Add expectation diff logs #1203
Conversation
@mroderick excited to get this in! Let me know what needs to be changed 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This absolutely seems like a nice addition. I just need to understand all the changes and why :-)
@@ -78,6 +78,11 @@ function mirrorPropAsAssertion(name, method, message) { | |||
var args = slice.call(arguments, 1); | |||
var failed = false; | |||
|
|||
// Hack to be replaced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a TODO statement. No one ever does anything to a TODO statement. Could you rather expand on your comment? I am not totally sure what this does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 82-84 check for one of the sinon match objects, and if found, revert to using the original message formatting without colored diffs. I did this to avoid making a lot of changes in a single PR, and because the choice to print a diff for a sinon match comparison is a little bit more ambigious than comparing two plain objects (What do I print for expect({x: true}).to.be.calledWith(match.falsy)
?). I was hoping one of the contributors could suggest a less hacky way to reserve the diff formatting just for plain object comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If this is explicitly to catch matchers, can you use the built-in
sinonMatch.isMatcher(...)
on line 82? - Can you update the comment to say why you're doing this (like some of the posted comment above) instead of this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Exactly what I was looking for, thank you 👍
@jdgreenberger great work on this. LGTM. |
@@ -78,6 +78,11 @@ function mirrorPropAsAssertion(name, method, message) { | |||
var args = slice.call(arguments, 1); | |||
var failed = false; | |||
|
|||
// Hack to be replaced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If this is explicitly to catch matchers, can you use the built-in
sinonMatch.isMatcher(...)
on line 82? - Can you update the comment to say why you're doing this (like some of the posted comment above) instead of this one?
@@ -199,7 +204,7 @@ mirrorPropAsAssertion( | |||
); | |||
mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); | |||
mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); | |||
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); | |||
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only calledWith
? Why not calledWithExactly
and others?
1 similar comment
@fearphage knowing about |
This now looks to be in great IMHO! Could I ask you just to clean up the commit history before merging? Just do an interactive rebase, or whatever you prefer, to get rid of the cleanup log commits. PS. I am not asking you to squash all the commits. They tell a good story. |
4af2809
to
6f346b3
Compare
@fatso83 updated! |
Perfect! Thanks for the work on this. |
No problem! Thanks for the review 😄 |
* See [Sinon #1203](sinonjs/sinon#1203)
Closes #104. Follows sinonjs/sinon#1203 mostly, although we still include the %* arguments list, as doing otherwise is a bit tricky for the negated case.
Purpose
Addresses issue #1179 by using npm libraries "diff" and "colors" to display colored diffs when arguments to
sinonSpy.calledWith
do not match the expectation.Background
Took a stab at implementing diffs for the base case of calledWith. In order to limit changes in this PR, there's a temporary hack to use the original formatting when arguments include sinon matchers. Would appreciate feedback on a better way to implement this, and any other architectural improvements.
Solution
Creates a new formatting type
%D
on spyApi.formatters inspy.js
to take the diff of expected and called arguments and created a useful colored message.Example:
How to verify -
Check the added tests in assert-test.js
npm install