Babel exceptions and assert.throws/assert.doesNotThrow breaks on class-call-check #3188
Closed
Description
In line https://github.com/nodejs/node/blob/master/lib/assert.js#L273 you will call the expected.call().
TypeError: Cannot call a class as a function
at exports.default (node_modules/babel-runtime/helpers/class-call-check.js:5:11)
at Object.WeirdError (node_modules/common/lib/exceptions.js:1:594)
at expectedException (assert.js:273:23)
at _throws (assert.js:310:8)
at assert.throws (assert.js:319:11)
The mocha test being run is
it('must throw when doSomething() fails',
function ()
{
assert.expect(1);
assert.throws(
function ()
{
util.doSomething();
}, WeirdError);
});
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()
else if (Error.isPrototypeOf(expected)) {
// it is safe to just return false here
return false;
}
Activity