-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
Is your feature request related to a problem? Please describe.
I was using assert(haystack.match(/needle/)); in my unit tests, and I found that assert.match(haystack, /needle/); produced much cleaner errors. +1, suggest to move to stable.
However, in a small handful of cases, I was also using the match results later on in the test, like so:
const m = haystack.match(/nee(\d+)le/);
assert(m);
// ...
assert(haystack2.match(m[1]));Describe the solution you'd like
If I could rescue the match results from assert.match, and if the regexp argument could be a string, this code could be simplified:
const m = assert.match(haystack, /nee(\d+)le/);
// ...
assert.match(haystack2, m[1]);Describe alternatives you've considered
This feature simply leads to cleaner tests.
Possible downsides are that people may overlook assert calls used like this, because they always expect "assert" to work like a C assertion, or having a return value is too inconsistent with the rest of the library.