-
Notifications
You must be signed in to change notification settings - Fork 392
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
fix: improved error messages #15
fix: improved error messages #15
Conversation
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 looks great! Thank you very much. Indeed developer experience matters a lot.
So far I just have a couple of questions/suggestions for your consideration. Let me know what you think.
src/to-have-attribute.js
Outdated
` ${expectedColor(printAttribute(name, expectedValue))}`, | ||
'Received:', | ||
` ${receivedColor(receivedAttribute)}`, | ||
].join('\n') |
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.
What was wrong with using getMessage
? Isn't this more or less the common pattern of message that getMessage
ensures?
I get why you removed its use from other cases (where the expect().to...
line made the expected part evident already), but in this case it looks like you're replicating what getMessage
already gives you.
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 is lazy fix for the case when receivedAttribute
is null
. Out of the box stringify in getMessage
will add quotes for already strings with escaping e.t.c.
Now i'm starting to think about removing 'Received:' part completely in such cases, but not so sure.
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.
Sorry for insisting, but what do you refer to with stringify in getMessage
? I don't see stringify being used in it.
I insist because in every case we can get away with using getMessage
is better, in case we change that format of messages we have a centralized way of doing it.
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, there is no stringify so it fails with Cannot read property 'match' of null
. Ok i will look into making it work with non-strings.
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.
Thank you very much!
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.
Fixed.You’re welcome!
'', | ||
`${receivedColor('received')} value must be an HTMLElement.`, | ||
printWithType('Received', received, printReceived), | ||
].join('\n') |
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.
How about using getMessage
here too? It could read something like this:
expect(element).toBeInTheDOM()
Expected:
<red>element</> must be an HTMLElement
Received:
object: <red>{\\"thisIsNot\\": \\"an html element\\"}</>"
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 is clone of the value must be a Promise
error message. 'Expected:' part is usually used when there are some arguments in the actual matcher e.g. as in toBeEqual
. Also printWithType
is not compatible with getMessage
, but too handy in this case.
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.
Ok, fine then.
5f2da18
to
e03132e
Compare
e03132e
to
7485879
Compare
Looks good now, thanks again. BTW, care to add yourself to the contributors list? It's ok if you don't want to. |
@microcood I merged your PR but the release is not working. Apparently there's a problem with the serialization of error messages into snapshots, because in environments such as Travis CI the terminal does not support the color codes, so the snapshots do not match. I found this issue jestjs/jest#4407 in jest's repo about it. Can you take a look into how this could be solved? From what they mention there, there should exist a way to customize the output with a serializer that would omit all the special coding of colors, but they do not link to it. If you can't I'll take a look at it later. |
I tentatively created #16, which I won't merge yet, but will probably merge it by the end of the day if I find no such serializer already provided or some other solution arises. If that's the case, you or someone else can happily provide a fix in a future PR supporting snapshots properly. |
I don't think that is a serializer issue - jest uses the same. So maybe it will make sense to look into CI config itself |
This is a temporary fix to a problem introduced in #15 that is preventing all the other goodness in that PR to be released.
🎉 This PR is included in version 1.3.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
I get it, will look into it, but in the mean time this PR fixes the "str.match is not a function" and "Cannot read property 'match' of null`" errors, so I prefer to have it out there. I'll try to bring back the snapshots one of these days, either with or without stripping out the ansi stuff. Will look into Travis' settings and possibly follow up open that travis issue you referred to. |
What:
Why:
User experience matters for developers too.
How:
Mostly by copying ideas from original jest/expect package.
Checklist: