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.

Error: Exceeded timeout of 5000 ms for a hook

See original GitHub issue

Describe the bug

Tests fails with an error: thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.”

Screenshot 2022-06-30 at 17 43 43

I tried to increase the timeout to one minute, but it didn’t help. I also tried turning fakeTimers on and off, but this also had no effect. Works fine when using with renderer.create(<Button {...props} />) from react-test-renderer package. Test example:

import 'react-native';
import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { Button } from '../Button';

describe('<Button />', () => {
  const props = {
    title: 'Test',
    onPress: jest.fn(),
  };

  it('should display a button', () => {
    const { getByTestId, getByText, queryByTestId, toJSON } = render(<Button {...props} />);
  });
});

Expected behavior

The test should pass without timeout error

Versions

  @testing-library/react-native: ^9.1.0 => 10.0.0 
  react: 17.0.2 => 17.0.2 
  react-native: 0.68.2 => 0.68.2 
  react-test-renderer: ^17.0.2 => 17.0.2

Jest Config

{
  "configs": [
    {
      "automock": false,
      "cache": true,
      "cacheDirectory": "/private/var/folders/hk/yj6yrf8s5wz__zwq5d55bqv00000gn/T/jest_dx",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/"
      ],
      "cwd": "/Users/user/Documents/Projects/App",
      "detectLeaks": false,
      "detectOpenHandles": false,
      "errorOnDeprecated": false,
      "extensionsToTreatAsEsm": [],
      "fakeTimers": {
        "enableGlobally": true
      },
      "forceCoverageMatch": [],
      "globals": {
        "ts-jest": {
          "diagnostics": {
            "exclude": [
              "**"
            ]
          }
        }
      },
      "haste": {
        "defaultPlatform": "ios",
        "platforms": [
          "android",
          "ios",
          "native"
        ]
      },
      "id": "d4fded5383daa5cad95de31c33ba7c39",
      "injectGlobals": true,
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "ts",
        "tsx",
        "js",
        "jsx",
        "json",
        "node"
      ],
      "moduleNameMapper": [
        [
          ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$",
          "identity-obj-proxy"
        ],
        [
          "^@/(.*)$",
          "/Users/user/Documents/Projects/App/src/$1"
        ]
      ],
      "modulePathIgnorePatterns": [],
      "prettierPath": "prettier",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/user/Documents/Projects/App",
      "roots": [
        "/Users/user/Documents/Projects/App"
      ],
      "runner": "/Users/user/Documents/Projects/App/node_modules/jest-runner/build/index.js",
      "sandboxInjectedGlobals": [
        "Math"
      ],
      "setupFiles": [
        "/Users/user/Documents/Projects/App/node_modules/react-native/jest/setup.js",
        "/Users/user/Documents/Projects/App/jest.setup.js"
      ],
      "setupFilesAfterEnv": [
        "/Users/user/Documents/Projects/App/node_modules/@testing-library/jest-native/extend-expect.js",
        "/Users/user/Documents/Projects/App/jest.setup.js",
        "/Users/user/Documents/Projects/App/jest.env.js"
      ],
      "skipFilter": false,
      "slowTestThreshold": 5,
      "snapshotSerializers": [],
      "testEnvironment": "/Users/user/Documents/Projects/App/node_modules/jest-environment-jsdom/build/index.js",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [
        "**/__tests__/**/*.[jt]s?(x)",
        "**/?(*.)+(spec|test).[tj]s?(x)"
      ],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      "testRegex": [],
      "testRunner": "/Users/user/Documents/Projects/App/node_modules/jest-circus/runner.js",
      "transform": [
        [
          "^.+\\.tsx?$",
          "/Users/user/Documents/Projects/App/node_modules/ts-jest/dist/index.js",
          {}
        ],
        [
          "^.+\\.svg$",
          "/Users/user/Documents/Projects/App/svgTransform.js",
          {}
        ],
        [
          "^.+\\.(js|ts|tsx)$",
          "/Users/user/Documents/Projects/App/node_modules/babel-jest/build/index.js",
          {}
        ],
        [
          "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$",
          "/Users/user/Documents/Projects/App/node_modules/react-native/jest/assetFileTransformer.js",
          {}
        ]
      ],
      "transformIgnorePatterns": [
        "/node_modules/(?!@react-native|react-native)"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": 0,
    "changedFilesWithAncestor": false,
    "ci": false,
    "collectCoverage": false,
    "collectCoverageFrom": [],
    "coverageDirectory": "/Users/user/Documents/Projects/App/coverage",
    "coverageProvider": "babel",
    "coverageReporters": [
      "json",
      "text",
      "lcov",
      "clover"
    ],
    "detectLeaks": false,
    "detectOpenHandles": false,
    "errorOnDeprecated": false,
    "expand": false,
    "findRelatedTests": false,
    "forceExit": false,
    "json": false,
    "lastCommit": false,
    "listTests": false,
    "logHeapUsage": false,
    "maxConcurrency": 5,
    "maxWorkers": 7,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "notifyMode": "failure-change",
    "onlyChanged": false,
    "onlyFailures": false,
    "passWithNoTests": false,
    "projects": [],
    "rootDir": "/Users/user/Documents/Projects/App",
    "runTestsByPath": false,
    "skipFilter": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testSequencer": "/Users/user/Documents/Projects/App/node_modules/@jest/test-sequencer/build/index.js",
    "updateSnapshot": "new",
    "useStderr": false,
    "watch": false,
    "watchAll": false,
    "watchman": true
  },
  "version": "28.1.1"
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
cybafelocommented, Nov 8, 2022

Oh great - close an issue simply because no one cares to fix it

jest.setTimeout SIMPLY DOES NOT WORK

image

and result:

image

Fix your jest it’s BROKEN

1reaction
mdjastrzebskicommented, Nov 8, 2022

@cybafelo:

  1. The issue has been closed as there was no repro repository, so we could not reproduce the error locally on our machines and the OP did not respond for feedback for more than a month. In such case there is nothing we can do about the issue.

  2. Your code screenshot does not seem to contain any RNTL-specific code. Maybe you should report your issue to Jest in such case?

If it indeed relates to RNTL, then please file a new GH issue & provide a minimal repro repository based on ours examples/basic example app. We can only try to help our uses if we can reproduce the problems they are facing.

  1. Finally, a kind reminder that we offer RNTL for free as our contribution to the wide RN community. We try to built the best tool we can, we value our users and try to help them solve the issues with RNTL the best we can BUT you are NOT entitled in any way for our support if you continue to rude. Please go somewhere else with your attitude.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceeded timeout of 5000 ms for a test · Issue #11607 - GitHub
I have started getting this issue: thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout ...
Read more >
Message "Async callback was not invoked within the 5000 ms ...
The default timeout value is 5000 (5000 ms - 5 seconds). This will be applicable for all test cases. Or if you want...
Read more >
thrown: "exceeded timeout of 5000 ms for a hook. use jest ...
thrown: "exceeded timeout of 5000 ms for a hook. use jest.settimeout(newtimeout) to increase the timeout value, if this is a long-running test.".
Read more >
Unable to test my API with Jest : r/node - Reddit
However, while trying to do an integration test, I got this error: thrown: "Exceeded timeout of 5000 ms for a test. Use jest....
Read more >
jest.setTimeout JavaScript and Node.js code examples
Set the default timeout interval for tests and before/after hooks in milliseconds. Note: The default timeout interval is 5 seconds if this method...
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