TypeError: _fakeTimers(…).JestFakeTimers is not a constructor
Steps to reproduce the behavior:
test: 'jest' script in package.json# 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.
The RUN npm test should successfully run the test cases
NA
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
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)
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)
@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
i was not that radical, instead i checked the yarn.lock file, and upgraded dependencies that were using older version of jest.
This article pointed me out to the solution:
yarn add jest-environment-jsdom-sixteen --dev
in jest.config.js
testEnvironment: 'jest-environment-jsdom-sixteen'
Sounds like version mismatches - does anyone have a reproduction?
Most helpful comment
@icsaba @JadenH @zameer-ansari I had the same error. I resolved it by deleting
node_modulesfolder and the lock file (in my case, I deletedyarn.lock) and reinstalled everything and now it works. I hope this resolves it for you