-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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.ok()
throwing AssertionError
instead of provided Error
object
#50780
Comments
Lines 396 to 398 in 25fdb48
It clearly re-thrown if the message is instanceof A minimal repo shown it is working correctly. import { ok } from 'assert/strict'
ok(false, Error('here is error')) |
This working as expected and will throw to avoid reading a Node.js module, as doing so could potentially result in misleading errors being thrown from module. |
My fault... I'm using Jest, and forget it has problems with |
We could use the same algorithm as Lines 167 to 169 in 1858341
|
It's deprecated, and also it would not work for |
The function is deprecated, but not what it does. It works fine with child classes. |
I think it wouldn't, because on child classes, the prototype constructor name would be different of |
If you don't believe me, try it |
We can also add a check that looks |
I like the idea. |
Hello, I would like to try and work on this issue. |
What do you need? |
Seeing the discussion, I will try to implement both the methods mentioned to see if it actually throws the required error. Will update accordingly? |
The wrong Error class is being dispatched due to using Jest, it's a bug there due to how it manage native classes. Proper solution should be done there, but in addition to that, a |
So you initially want to check if a function similar to |
I think so, yes. |
@piranna Is there any way to get Jest to use my local nodejs? i.e the node I have in I tried searching around but can't find much. Maybe you have tried this before? |
Compile your Node.js, and launch Jest with It. |
I have compiled my node, how do I launch Jest with it? Is there some particular config option for it? Or a command line flag? |
|
Added the function for compliance with frameworks such as Jest Fixes: nodejs#50780
Added the function for compliance with frameworks such as Jest Fixes: nodejs#50780
Added the function for compliance with frameworks such as Jest Fixes: nodejs#50780
Added the function for compliance with frameworks such as Jest Fixes: nodejs#50780
Hi, can I work on this issue? |
Sure, go for it :-) |
is this issue still open ? |
Yes, it's still a problem. |
I noticed that this issue is stalled even though there is an almost accepted PR that solves the problem. PR: #53980 P.S.: I added the author of the PR and the commenter as co-authors in the commit. |
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Great, good work @pmarchini :-) |
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com> PR-URL: #53980 Fixes: #50780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Version
v20.9.0
Platform
Linux executive 6.5.0-10-generic #10-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 13 13:49:38 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
assert
What steps will reproduce the bug?
assert.ok()
docs says:I've called to it with an
Error
instance as second argument, and instead of being thrown that error, it's being thrown anAssertionError
with it'smessage
field set to themessage
field of the provided error.Not sure what's the correct solution here, based on docs and common sense, the provided error should be thrown, but based on homogeneity, an
AssertionError
should be thrown (current behaviour) so it always throw anAssertionError
no matter what it's provided as second argument...How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
Not sure if it's a bug, or a documentation issue.
What do you see instead?
AssertionError
is thrown, with provided Errormessage
.Additional information
No response
The text was updated successfully, but these errors were encountered: