-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
assert: add default operator to assert.fail()
#22694
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,8 +87,9 @@ function innerFail(obj) { | |
| function fail(actual, expected, message, operator, stackStartFn) { | ||
| const argsLen = arguments.length; | ||
|
|
||
| let internalMessage; | ||
| if (argsLen === 0) { | ||
| message = 'Failed'; | ||
| internalMessage = 'Failed'; | ||
| } else if (argsLen === 1) { | ||
| message = actual; | ||
| actual = undefined; | ||
|
|
@@ -106,13 +107,23 @@ function fail(actual, expected, message, operator, stackStartFn) { | |
| operator = '!='; | ||
| } | ||
|
|
||
| innerFail({ | ||
| if (message instanceof Error) throw message; | ||
|
|
||
| const errArgs = { | ||
| actual, | ||
| expected, | ||
| message, | ||
| operator, | ||
| operator: operator || 'fail', | ||
|
||
| stackStartFn: stackStartFn || fail | ||
| }); | ||
| }; | ||
| if (message !== undefined) { | ||
| errArgs.message = message; | ||
| } | ||
| const err = new AssertionError(errArgs); | ||
| if (internalMessage) { | ||
| err.message = internalMessage; | ||
| err.generatedMessage = true; | ||
| } | ||
| throw err; | ||
| } | ||
|
|
||
| assert.fail = fail; | ||
|
|
||
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.
☝️ Should use the util for
isError(internal reference) for this since it avoids the error of errors from other realms.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.
Only changing this here is likely not the best way. It would have to be changed throughout assert in total or not at all. It is also sad that the util function is not a safe check as the
Symbol.toStringTagcould be set andisErrorwould happily return true in some weird cases.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.
Ah, didn't know this was consistent with the rest of
assert. A follow up would be best.Oh I thought the new
isNativeErrorwas more robust.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.
Oh, I missed the
isNativeErrorsomehow. We have multiple places in core where we should likely switch to this check.