-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
assert.match should return match result #33869
Copy link
Copy link
Closed
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Metadata
Metadata
Assignees
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Is your feature request related to a problem? Please describe.
I was using
assert(haystack.match(/needle/));in my unit tests, and I found thatassert.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:
Describe the solution you'd like
If I could rescue the match results from
assert.match, and if theregexpargument could be a string, this code could be simplified: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.