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

Created on 24 Aug 2020  ·  6Comments  ·  Source: facebook/jest

🐛 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

Bug Report Needs Repro Needs Triage

Most helpful comment

@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

All 6 comments

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?

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

Was this page helpful?
0 / 5 - 0 ratings