-
Notifications
You must be signed in to change notification settings - Fork 142
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
Stringify objects better #84
Conversation
If a user is trying to debug a string, it's important that it be exact.
Looks like it works. The previous system would blow up on circular objects (b/c it was using native JSON), would jam everything into one line, and would double-quote keys b/c JSON. So the output of an argument changes from: |
I just realized that failed verifications that contain matchers are reallllllly ugly. If I say: someTestDouble(55)
td.verify(someTestDouble(td.matchers.isA(String))) I get this monstrosity: Unsatisfied verification on test double.
Wanted:
- called with `({
__matches: function (actual) {
if (type === Number) {
return _.isNumber(actual);
} else if (type === String) {
return _.isString(actual);
} else if (type === Boolean) {
return _.isBoolean(actual);
} else {
return actual instanceof type;
}
}
})`.
But was actually called:
- called with `(55)`. I think we should probably figure out a custom toString for matcher args; maybe based on function name? |
Looks like we're good to merge! The above monstrosity will now print much more nicely as: """
Unsatisfied verification on test double.
Wanted:
- called with `(isA(String))`.
But was actually called:
- called with `(55)`.
""" Huzzah!! |
cc / @BrianGenisio & @BaseCase -- since I've chatted with both of you about custom matchers before, I wanted to give you the heads up that this new feature is available. |
@searls Nifty! I'll see about supporting this in testdouble-chai sometime soon. 🆒 |
@BaseCase I'm also thinking about adding some metadata to the errors that verify throws. I assume that you're catching the errors to map to chai assertions? |
@searls Right now it catches all |
Right now, a lot of logging in
explain
andverify
will give up and print[Object object]
sort of strings, when it'd be much rather to print them out. I forked and published this module to do most of the heavy liftingtd.matchers.create()
API, as the scheme for printing their names becomes more complicatedtd.matchers.create()