Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: _fakeTimers(…).JestFakeTimers is not a constructor #10441

Closed
xameeramir opened this issue Aug 24, 2020 · 11 comments
Closed

TypeError: _fakeTimers(…).JestFakeTimers is not a constructor #10441

xameeramir opened this issue Aug 24, 2020 · 11 comments

Comments

@xameeramir
Copy link

xameeramir commented Aug 24, 2020

πŸ› Bug Report

TypeError: _fakeTimers(…).JestFakeTimers is not a constructor

To Reproduce

Steps to reproduce the behavior:

  • Write test cases in Node js project
  • Set test: 'jest' script in package.json
  • Set a docker container with the following Dockerfile
# Dockerfile
FROM node:12.14.1-alpine

RUN mkdir /usr/app

WORKDIR /usr/app

COPY . /usr/app
RUN apk update && apk upgrade && apk add --no-cache git
RUN npm install -g jest
RUN npm i
RUN npm test
CMD npm start

The node_modules is always re-created from scratch while creating the Docker image.

Expected behavior

The RUN npm test should successfully run the test cases

Link to repl or repo (highly encouraged)

NA

envinfo

System:
    OS: Linux 4.19 Alpine Linux
    CPU: (2) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  Binaries:
    Node: 12.14.1 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.2.2 => 26.4.2

Crosspost on Stackoverflow: https://stackoverflow.com/q/63522963/2404470

@JadenH
Copy link

JadenH commented Aug 25, 2020

I've run into this as well. Here is a stack trace:

TypeError: _fakeTimers(...).JestFakeTimers is not a constructor

      at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:149:23)

@icsaba
Copy link

icsaba commented Aug 26, 2020

i have the same error, just with jest-environment-node

TypeError: _fakeTimers(...).JestFakeTimers is not a constructor

      at new NodeEnvironment (../node_modules/jest-environment-node/build/index.js:121:23)

@osshad
Copy link

osshad commented Sep 4, 2020

@icsaba @JadenH @zameer-ansari I had the same error. I resolved it by deleting node_modules folder and the lock file (in my case, I deleted yarn.lock) and reinstalled everything and now it works. I hope this resolves it for you

@icsaba
Copy link

icsaba commented Sep 10, 2020

i was not that radical, instead i checked the yarn.lock file, and upgraded dependencies that were using older version of jest.

@joel
Copy link

joel commented Nov 3, 2020

This article pointed me out to the solution:

yarn add jest-environment-jsdom-sixteen --dev

in jest.config.js

testEnvironment: 'jest-environment-jsdom-sixteen'

@SimenB
Copy link
Member

SimenB commented Nov 4, 2020

Sounds like version mismatches - does anyone have a reproduction?

https://stackoverflow.com/help/minimal-reproducible-example

@Cedricvb
Copy link

Cedricvb commented Dec 1, 2020

What worked for me, was adding this to package.json:

"resolutions": { "jest-environment-jsdom": "^26.0.1" }

@oguzhnatly
Copy link

Adding this to package.json, worked for me too. Thanks, @Cedricvb!

"resolutions": { 
  "jest-environment-jsdom": "^26.0.1"
},

@natezhengbne
Copy link

The result of the 'yarn test' on the local machine is absolutely fine.
The test was only breaked on Bitbucket pipeline.

@SimenB
Copy link
Member

SimenB commented Mar 14, 2021

If you're having issues on CI but not locally it's likely to be an issue with your install - using a lockfile might help.


As this still hasn't gotten a reproduction I'll close this.

@SimenB SimenB closed this as completed Mar 14, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants