-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
🚀 Feature Proposal
Error.cause has been freshly added to the JavaScript language (https://tc39.es/ecma262/#sec-error-message) and makes chaining errors easier than ever.
Motivation
Error.cause is a very useful feature. It would be very useful if it would be possible to test Error.cause with jest
Related: #11935
Example
toThrowError could accept cause as an additional property:
test('getJson - error', async () => {
const mockError = new SyntaxError('Unexpected token')
Ajax.getJson = jest.fn(() => {
throw mockError
})
await expect(Ajax.getJson('https://example.com')).rejects.toThrowError({
message: 'Failed to fetch "https://example.com"',
cause: mockError, // support this
})
})Pitch
It is a core feature of the javascript language and would be very useful.
conartist6, PaperStrike, bgoscinski, TheAlexLichter, sstone1 and 9 moreTheAlexLichter and andrebnassis