-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Best practice assertions for string inclusion and dynamic regex #381
Comments
t.regex has now effectively solved one of my 2 issues. |
@twada @jamestalmage perhaps you could provide some insight into this? |
AVA now prints all values. |
I am not seeing that happening. t.true(a.includes(b)) prints only Value is not `true`:
false |
@zvictor well I wrote that three years ago 😉 AVA no longer prints all values. Per https://github.com/avajs/ava/blob/master/docs/03-assertions.md#enhanced-assertion-messages this requires you to enable Babel, and it only works with |
Today, I've run into two cases where I ended up writing helpers to get better errors. After writing them, I realized that it is somewhat against the spirit of "just writing assertions and getting readable errors". So I'd like to find out what you think is best practice here and whether it might make sense to expand what power-assert is displaying.
String inclusion
I've got some big dynamic string and want to make sure it contains another dynamic string. So I wrote
When this fails, it will print the value of
shortString
and the return value of.includes()
, which is false, but will not show me the value ofbigString
, which I need to properly debug it. So either I re-run the test with a console.log or I create helpers and refactor toIn the case of a failure, this will print both bigString and shortString, allowing me to figure out what went wrong at the first glance.
Dynamic Regex
I've got a dynamic regex and want to run it against another dynamic string. So I wrote
Like in the above case, when this fails, it will print the value of
dynamicString
and the return value of.test()
, which is false, but will not show me the value ofdynamicRegex
, which I need to properly debug it. I could usedynamicString.match(dynamicRegex)
, which will show the value ofdynamicRegex
, but it will also hide the value ofdynamicString
. So, like above, I wrote a helperConclusion
I'm guessing that power-assert avoids printing the top level object by default to avoid visual clutter, but in the case of strings and regex-objects (and probably numbers and booleans, as well), I would find it useful to print them.
This might end up being a power-assert issue, feel free to point that out and I will close & create an issue at its repo.
The text was updated successfully, but these errors were encountered: