Async tests are no longer reporting the correct failure conditions if not surrounded by a try/catch. Instead, the error is
TypeError: jasmine.Spec.isPendingSpecException is not a function
at returnValue.then.error (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:112:28)
Steps to reproduce the behavior:
async function asyncOne () {
return Promise.resolve(1)
}
describe('asyncTests', () => {
it('should fail because expected does not match received', async () => {
const asyncResult = await asyncOne()
expect(asyncResult).toBe(2)
})
it('should fail because expected does not match received', async () => {
expect(await asyncOne()).toBe(2)
})
it('works with try/catch', async () => {
try {
const asyncResult = await asyncOne()
expect(asyncResult).toBe(2)
} catch (e) {
fail(e)
}
})
})
The first two tests above should fail because the expected, 2, does not match the received, 1. Instead they are failing with the error:
TypeError: jasmine.Spec.isPendingSpecException is not a function
at returnValue.then.error (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:112:28)
The third test is behaving as expected.
This was introduced in version 24.0.0, if you run the test above on version 23.6.0, it is working as expected.
Test code is above
npx envinfo --preset jestPaste the results here:
npx: installed 1 in 3.045s
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 8.15.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
jest: 24.0.0 => 24.0.0
I cannot reproduce. Could you please provide your config, or if you don't mind could create a full repo?
Looks like it is an Intellij IDEA Issue or a combination of the two. They have a custom reporter that no longer works in version 24.0.0. I have reproduced the error in the following project: https://github.com/pbohnenkamp/jest-issue-7747
IDEA runs the test with the command line:
/usr/local/bin/node --require "/Applications/IntelliJ IDEA.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-stdin-fix.js" /Users/.../projects/jest-issue-7747/node_modules/jest/bin/jest.js --colors --reporters "/Applications/IntelliJ IDEA.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js" --verbose --runTestsByPath /Users/.../projects/jest-issue-7747/asyncExample.spec.js
If you use npm run test, it will use that command line as I have also copied in the specific IDEA files that are referenced. You can see the error in the output:
##teamcity[testSuiteStarted nodeId='99127_392229_442430007-1' parentNodeId='/Users/BOH9017/projects/jest-issue-7747/asyncExample.spec.js' name='asyncTests' running='true' nodeType='suite' locationHint='suite:///Users/BOH9017/projects/jest-issue-7747/asyncExample\.spec\.js.asyncTests']
##teamcity[testStarted nodeId='99127_392229_442430007-2' parentNodeId='99127_392229_442430007-1' name='should fail because expected does not match received' running='true' nodeType='test' locationHint='test:///Users/BOH9017/projects/jest-issue-7747/asyncExample\.spec\.js.asyncTests.should fail because expected does not match received']
##teamcity[testFailed nodeId='99127_392229_442430007-2' duration='7' message='TypeError: jasmine.Spec.isPendingSpecException is not a function' details='|n [2mat returnValue.then.error ([22mnode_modules/jest-jasmine2/build/jasmineAsyncInstall.js[2m:112:28)[22m']
If you just run the command `./node_modules/.bin/jest' it works fine.
Not sure what you want to do with it. I am going to open a bug with Intellij too and will post a link to it.
Please share the link when you've created the issue.
We'll probably be changing our reporter API to not match jasmine at some point as well, so it'd be good if they could not rely on at least the parts that are not documented. I'll try to ping them before we do anything drastic, though 馃檪
Link to issue:
https://youtrack.jetbrains.com/issue/WEB-37021
Most helpful comment
Link to issue:
https://youtrack.jetbrains.com/issue/WEB-37021