question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'addExpectationResult' of undefined

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
patrickhulcecommented, May 6, 2018

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.

5reactions
christopher-franciscocommented, Jun 5, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest error: TypeError: Cannot read properties of undefined ...
TypeError : Cannot read properties of undefined (reading 'send'). It is because there is no res object in the getAllUsers function.
Read more >
Cannot read property 'addExpectationResult' of undefined
Cannot read property 'addExpectationResult' of undefined.
Read more >
Ticket: Projection Test for 3 entries not passing - MongoDB
(node:10351) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined (node:10351) ...
Read more >
cannot read property 'pathname' of undefined jest - You.com
The tests run and fail and then this error is thrown in jest 22. TypeError: Cannot read property 'addExpectationResult' of undefined at Env.fail...
Read more >
jest: Cannot read property 'find' of undefined - YouTrack
jest: Cannot read property 'find' of undefined. when I run on terminal "npm run test" or run npm script through webstorm, all runs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found