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.

Jest hangs on invalid expectation(s)

See original GitHub issue

TL;DR The issue is specific to Node 10.0.0; Try upgrading to 10.1.0 or above.

🐛 Bug Report

If my there is at least one expectation in my unit test that is not fulfilled at test time, the entire test suite “hangs” instead of reporting a failed (“red”) test.

(On contrary, If all my expectations are fulfilled at test time, the tests does not seem to hang.)

To Reproduce

The following test code is an example.

describe(`Demo`, () => {
  it(`Should Fail, not Hang`, () => {
    expect(1).toEqual(2);
  });
});

Run Jest from Git Bash/CMD, observe the following output:

$ yarn test
yarn run v1.6.0
(node:3316) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ jest -i

 RUNS  __tests__/3-1-single-array-multiple-stacks.spec.ts

Software/Package Versions:

jest: 22.4.3
ts-jest: 22.4.5

$ node --version
v10.0.0

$ npm --version
6.0.0

$ npm --version
6.0.0

$ tsc --version
Version 2.8.3

Expected behavior

The test should be reported as failing.

Run npx envinfo --preset jest

$ npx envinfo --preset jest
npx: installed 1 in 5.897s

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i5-3317U CPU @ 1.70GHz
  Binaries:
    Yarn: 1.6.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.0.0 - ~\AppData\Roaming\npm\npm.CMD

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, May 9, 2018

It does not hang on node 10.1.0, though. Maaaaybe related to https://github.com/nodejs/node/pull/20266?

1reaction
SimenBcommented, May 9, 2018

It hangs when I use Node 10

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - jest hangs indefinitely, runs no tests - Stack Overflow
I have discovered a workaround which is to run using the --runInBand flag, which just runs tests in the same thread: jest --runInBand....
Read more >
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​.
Read more >
Jest Testing like a Pro - Tips and tricks
toBe(expected) // Object.is equality Expected: 10 Received: 50. clearly let you figure out that something is wrong with the cap, and in this ......
Read more >
Why Jest freezes after tests run? (Jest hangs indefinitely)
If you noticed that Jest (npm / yarn) test hang at the end of the test execution while you run tests in parallel...
Read more >
How to Test Asynchronous Code with Jest | Pluralsight
The above test is a false positive. The test will pass but the assertion should make it fail. Jest will run the test...
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