chai
chai copied to clipboard
expected [Function] to throw 'RangeError' but 'RangeError' was thrown
Case:
describe.only('reproduce RangeError bug', () => {
it('should throw range error', () => {
expect(() => {
throw RangeError
}).to.throw(RangeError)
})
it('should throw range error using constructor', () => {
expect(() => {
throw new RangeError('test')
}).to.throw(RangeError)
})
})
Expected: both tests pass
Actual:
main tests (en-US)
reproduce RangeError bug
1) should throw range error
✓ should throw range error using constructor
main tests (fr-CA)
reproduce RangeError bug
2) should throw range error
✓ should throw range error using constructor
2 passing (26ms)
2 failing
1) main tests (en-US)
reproduce RangeError bug
should throw range error:
AssertionError: expected [Function] to throw 'RangeError' but 'RangeError' was thrown
+ expected - actual
at Context.<anonymous> (test/main.spec.ts:3:6840)
at processImmediate (internal/timers.js:456:21)
2) main tests (fr-CA)
reproduce RangeError bug
should throw range error:
AssertionError: expected [Function] to throw 'RangeError' but 'RangeError' was thrown
+ expected - actual
at Context.<anonymous> (test/main.spec.ts:3:6840)
at processImmediate (internal/timers.js:456:21)
I see there is a check-error
library, is it required in order to detect RangeErrors
?
Potential answer?
Right now Chai is designed as such that only subclasses of Error can be thrown. We believe this is how code should be written.
https://github.com/chaijs/chai/issues/1175#issuecomment-407477330