Skip to content
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

assert: prefer reference comparison over string comparison #41015

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/assert.js
Expand Up @@ -832,7 +832,7 @@ function expectsError(stackStartFn, actual, error, message) {
details += ` (${error.name})`;
}
details += message ? `: ${message}` : '.';
const fnType = stackStartFn.name === 'rejects' ? 'rejection' : 'exception';
const fnType = stackStartFn === assert.rejects ? 'rejection' : 'exception';
innerFail({
actual: undefined,
expected: error,
Expand Down Expand Up @@ -879,7 +879,7 @@ function expectsNoError(stackStartFn, actual, error, message) {

if (!error || hasMatchingError(actual, error)) {
const details = message ? `: ${message}` : '.';
const fnType = stackStartFn.name === 'doesNotReject' ?
const fnType = stackStartFn === assert.doesNotReject ?
'rejection' : 'exception';
innerFail({
actual,
Expand Down Expand Up @@ -993,7 +993,7 @@ function internalMatch(string, regexp, message, fn) {
'regexp', 'RegExp', regexp
);
}
const match = fn.name === 'match';
const match = fn === assert.match;
if (typeof string !== 'string' ||
RegExpPrototypeTest(regexp, string) !== match) {
if (message instanceof Error) {
Expand Down