Skip to content

jest.useRealTimers() is not a function when running RTL tests in jest-electron environment #905

Closed
@Manish3323

Description

@Manish3323

I decided to try using jest-electron environment in our jest test setup because jsdom environment has some missing browser functionality that we were using.

  • "@testing-library/jest-dom": "^5.11.9",
  • "@testing-library/react": "^11.2.3",
  • "@testing-library/user-event": "^12.6.3",
  • node version: v15.10
  • npm version: v7

Relevant code or config:

pasting only necessary changes here of my jest.config.js

{
 .
 .
  runner: 'jest-electron/runner',
  testEnvironment: 'jest-electron/environment',
  .
  .
  .
}

What you did:

ran npm run test

What happened:

i think helpers file inside RTL /dom is calling jest.useFakeTimers()..
which is not available in jest-electron environment.

The error that i'm getting is shown in the following SS.
Screenshot 2021-02-27 at 1 16 00 PM

Reproduction:

Small repro can be created on local machine on following these steps.
clone : https://github.com/tmtsoftware/esw-ocs-eng-ui
git checkout jest-branch
npm i & npm t

Problem description:

RTL/jest-dom helpers are calling jest.timers functionality without checking jest-environment.

Suggested solution:

there could be some kind of check related to which environment jest is currently running before this line.
@Testing-Library/dom/dist/helpers.js:38.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions