Amir Rossert
Amir Rossert

Reputation: 1053

Jest not showing errors that are thrown

I'm using jest for my unit tests and I have an issue when my code throws an unexpected exception, jest is not handling it.

For example:

async function func() {
    throw new Error('ERROR');
}

test('test', async () => {
    await func();
});

I would expect from jest to show me where is the exception but all I get is:

TypeError: jasmine.Spec.isPendingSpecException is not a function

  at returnValue.then.error (node_modules/jest-config/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:112:28)

Should I wrap the test function with try/catch and use fail() on the catch block?

I'm using the latest 24.0.0 version.

Upvotes: 4

Views: 4462

Answers (1)

phil b
phil b

Reputation: 36

I just ran into this myself. In my case, it is caused by a custom reporter that Intellij IDEA uses that is not compatible with version 24.0.0. If you downgrade to 23.6.0 it will work as you expect. To get the actual test error in version 24.0.0 just wrap the await statement in a try/catch like so:

test('test', async () => {
     try {
         await func();
     } catch (e) {
         fail(e)
     }
})

I have submitted an issue with Intellij. If you want to track the issue: jest-intellij-reporter is failing with TypeError

Upvotes: 2

Related Questions