Cannot read property 'addExpectationResult' of undefined
See original GitHub issueDo you want to request a feature or report a bug? A bug
What is the current behavior?
In Jest 20, everything works fine. In Jest 21/22 I get this behavior. It happens on all computers I have attempted to test this project on. I have tried to remove node_modules and yarn.lock.
The tests run and fail and then this error is thrown in jest 22.
TypeError: Cannot read property 'addExpectationResult' of undefined
at Env.fail (***/node_modules/jest-jasmine2/build/jasmine/Env.js:465:24)
at next.fail (***/node_modules/jest-jasmine2/build/queue_runner.js:48:22)
at <anonymous>
In Jest 21, this error is thrown:
TypeError: Cannot read property 'addExpectationResult' of undefined
at Env.fail (***/node_modules/jest-jasmine2/build/jasmine/Env.js:510:24)
at next.fail (***/node_modules/jest-jasmine2/build/queue_runner.js:42:22)
at <anonymous>
The tests run with jest --runInBand --watch
as they test database procedures. When I remove --watch
, the error disappears, but the tests do not seem to run in sequence as they still fail.
A typical test file looks something like this:
import taskProvider from './somewhere'
const { db, seed } = global.testDependencies
let task
beforeEach(async () => {
await db.migrate.latest()
await seed()
task = taskProvider({ db })
})
afterEach(async () => {
await db.migrate.rollback()
})
afterAll(async () => {
await db.destroy()
})
describe('something something', () => {
it('somethings', async () => {
await task({ foo: 'bar' })
expect(await db.where({ foo: 'bar' }).length).not.toBe(0)
})
})
What is the expected behavior? Tests should run normally and no error should occur.
Please provide your exact Jest configuration
"jest": {
"setupFiles": [
"<rootDir>/testUtil/testSetup.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/testUtil/testFramework.js"
}
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Binaries:
Node: 8.9.2
Yarn: 1.5.1
npm: 5.5.1
npmPackages:
jest:
wanted: ^22.4.3
installed: 22.4.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:19 (1 by maintainers)
Top GitHub Comments
FWIW I also ran into this and was led to this issue. Only happened in CI when an async test timed out but the underlying action continued until after the test suite finished (and I’m guessing the callback tried to add the result of the expectation). I could never get it to happen locally though.
@patrickhulce were you able to fix this? I have the exact same behavior as you do. It doesn’t happen on locally. Only on my Jenkins CI server.