-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Babel exceptions and assert.throws/assert.doesNotThrow breaks on class-call-check #3188
Comments
Especially if you're working with new and shiny stuff via Babel, you will be better off using a more robust userland alternative. Unfortunately, the issue you cite here is far from the only shortcoming of the library when dealing with ES6. The Assert API is locked (although the web site hasn't caught up to that yet, but it will soon) and is unlikely to be improved substantially unless its defects are causing problems with the Node.js project tests. Because of that, I'm going to close this. I'm not a fan of emoticons in GitHub issue text, but I don't see how I can actually close this without a :-/ and a :-(. So: :-/ :-( |
@Trott so I need my custom error check or throws() assertion to overcome this problem. That is fine with me, as I have been working on that anyway. Sad though, that such defects in the software will not be fixed, even though the change is only small and with the least of impact. Even more so with node now being joined with iojs, again and their overall commitment towards ES6+ and standards compliance. Of course, a lot of APIs out there use the call class pattern in favor or as a fall back in case the user forgot the new keyword... |
@Trott please reopen. since node does support harmony classes and classes by default do not support being called without using the new operator I strongly believe this to be a bug in node. |
isn't that a limitation of the spec? |
@evanlucas I think @silkentrance is talking about how this fails:
Putting this in
The question is whether the implementation needs to be fixed so that it works with ES6 classes or whether the documentation needs to be updated to reflect that the second argument to
That was written before ES6 class constructors were a thing. @silkentrance As a workaround, you can pass a validation function instead of a constructor. Based on my sense of the viewpoint of @nodejs/tsc the last time this was discussed there, I suspect the project will opt for the documentation fix. Honestly, I feel like the Anyway, re-opening because this should probably get a doc update at an absolute minimum. |
@Trott thanks, I managed to come over this, though, by implementing the following in my esaver project: https://github.com/coldrye-es/esaver/blob/master/src/node.es#L45 It will inject a custom check function instead of the error subclass unless the user did not provide a custom check. However, making that a functionality of node's assert would be so much better. Especially since node must expect users to subclass And, please, this should not be fixed by simply documenting a special case but instead by compensating for and expecting any specification limitations. Subsequently, of course, reopening the module for further development as it clearly does not meet the new requirements. |
There's an error in my ES6 class above. When I correct the error, things work as expected. This code works fine:
Is it remotely possible that there's a similar error in your ES6 class, @silkentrance? If not, can you modify the above code (or create your own) to make a minimal test showing the issue? |
Well, what I am using is simply
|
@Trott in your functionThatThrows() you should not throw an instance of the expected error as this will suffice the instanceof check in assert/expectedException(). |
Ah! OK, so this code below should throw an
|
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError` if used with an ES6 class that extends Error. Fixes: nodejs#3188
Suggested fix in #4166 |
This is fixed in master and should be in 5.2.1 (or 5.3.0 if 5.2.1 is not the next release). |
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError` if used with an ES6 class that extends Error. Fixes: nodejs#3188 PR-URL: nodejs#4166 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError` if used with an ES6 class that extends Error. Fixes: nodejs#3188 PR-URL: nodejs#4166 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
In line https://github.com/nodejs/node/blob/master/lib/assert.js#L273 you will call the expected.call().
The mocha test being run is
Of course, doSomething() does not yet throw the WeirdError, instead it will throw TypeError.
Now, in expectedException(), WeirdError will be assumed a callable, however, with Babel/es classes, this is no longer true as the new keyword must be used to construct instances of that type.
Would it be possible to add additional expected.prototype tests before trying to call upon the exception class?
E.g. before line https://github.com/nodejs/node/blob/master/lib/assert.js#L273 one would add something like this to avoid expected.call()
The text was updated successfully, but these errors were encountered: