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.

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

See original GitHub issue

🐛 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:11

github_iconTop GitHub Comments

5reactions
Cedricvbcommented, Dec 1, 2020

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

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

2reactions
oguzhnatlycommented, Feb 13, 2021

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

"resolutions": { 
  "jest-environment-jsdom": "^26.0.1"
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: _fakeTimers(...).JestFakeTimers is not a constructor
I have a Node js server which has some tests running with jest . The result of the npm test ON LOCAL MACHINE...
Read more >
Timer Mocks - Jest
In the following example we enable fake timers by calling jest. ... At this point in time, the callback should not have been...
Read more >
jest.useFakeTimers JavaScript and Node.js code examples
useFakeTimers (); const spy = jest.fn(); delay(100).then(spy); expect(spy).not.toBeCalled(); // Fast-forward until all timers have been executed jest.
Read more >
Problems with using useFakeTimers('modern') in a create ...
Use the new fake timers approach from Jest 26: jest. ... /jest-fix-the-not-wrapped-in-act-warning-with-jest-fake-timers. act(() => { jest.
Read more >
TypeError: StoryblokClient is not a constructor : r/webdev
hey, as you can see here storyblokClient is definetly an object, however when I use it like that it throws this error (note:...
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