Giter VIP home page Giter VIP logo

jest-reproducible-case's Introduction

Test timing issue with jest

Follow these instructions to reproduce the problem:

Clone repository

git clone [email protected]:juan-fernandez/jest-reproducible-case.git

Install dependencies

cd jest-reproducible-case
yarn

Run Button.test.tsx test

yarn test Button.test.tsx --no-cache

See the error is the following:

 FAIL  ./Button.test.tsx
  tests
    ✕ should show login form (609 ms)
    ✓ should show login form 2 (393 ms)

  ● tests › should show login form

    thrown: "Exceeded timeout of 400 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      13 |
      14 | describe('tests', () => {
    > 15 |   test('should show login form', async () => {
         |   ^
      16 |     await runTest()
      17 |   })
      18 |   test('should show login form 2', async () => {

      at Button.test.tsx:15:3
      at Object.<anonymous> (Button.test.tsx:14:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        3.403 s

Run Button2.test.tsx test

This test file is exactly the same as Button.test.tsx but the order of the tests is changed:

yarn test Button2.test.tsx --no-cache
 FAIL  ./Button2.test.tsx
  tests
    ✕ should show login form 2 (577 ms)
    ✓ should show login form (378 ms)

  ● tests › should show login form 2

    thrown: "Exceeded timeout of 400 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      13 |
      14 | describe('tests', () => {
    > 15 |   test('should show login form 2', async () => {
         |   ^
      16 |     await runTest()
      17 |   })
      18 |   test('should show login form', async () => {

      at Button2.test.tsx:15:3
      at Object.<anonymous> (Button2.test.tsx:14:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        3.244 s

Outcome

Even though Button.test.tsx and Button2.test.tsx are running the same tests but in a different order, the only test that times out is the first one, regardless of what the tests are doing.

Expected outcome

The tests behave the same timing-wise.

jest-reproducible-case's People

Contributors

juan-fernandez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.