[Bug]: Jest 27 - useFakeTimers erases performance.mark and friends
See original GitHub issueVersion
27.3.1
Steps to reproduce
window.performance.mark = () => {}
jest.useFakeTimers()
assert(typeof window.performance.mark === 'undefined')
jest.useRealTimers()
assert(typeof window.performance.mark === 'function')
jest.useFakeTimers("legacy")
assert(typeof window.performance.mark === 'function')
Expected behavior
jest.useFakeTimers()
to not override global polyfills/mocks of performance.mark
Actual behavior
jest.useFakeTimers()
overrides global polyfills/mocks of performance.mark, and sets it to undefined
.
Additional context
I found a similar issue in @sinonjs/fake-timers
https://github.com/sinonjs/fake-timers/issues/136. Don’t know if it’s related to jest
though.
Environment
System:
OS: macOS 12.0.1
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 16.13.0 - /usr/local/bin/node
Yarn: 3.0.0-rc.9 - /opt/homebrew/bin/yarn
npm: 8.1.0 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Timer Mocks - Jest
In the following example we enable fake timers by calling jest.useFakeTimers() . This is replacing the original implementation of setTimeout() ...
Read more >Fix the "not wrapped in act(...)" warning with Jest fake timers
... to manually use act to avoid missing bugs in your code. In this lesson you'll learn how to identify the cause of...
Read more >mongoose | Yarn - Package Manager
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha). Build Status NPM...
Read more >Hands-On way to build Frontend with React | Nick Ovchinnikov
First will be a configuration of the ReactJS application with Typescript and using build tools Webpack+Babel. Second, there're presented TDD or TLD approaches ......
Read more >Test-Driven React - Library
Code, Jest, Babel, ESLint, Webpack, Enzyme, and many other tools. ... than revealing potential bugs that might occur under edge case conditions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The use-case is pretty straight-forward:
performance.mark()
somewhere deeply in its implementationperformance.mark()
and I’m fine with it just being a noop.performance.mark()
in mysetupFile.js
performance.mark()
always will be around so my tests don’t crash.I’d be ok with any way of making it happen, even things like
jest.useFakeTimers({ ignore: [window.performance] })
or whateverI think this issue could be fixed pretty easily be just making avoiding to fake
performance
. This is already possible by telling @sinonjs/fake-timers, but we have just forgot to update our docs … 🙈 Ref https://github.com/sinonjs/fake-timers/issues/409, https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56961#pullrequestreview-797296492 and https://github.com/sinonjs/fake-timers/issues/374.@SimenB I am not to well versed in Jest’s use of fake timers, but I do not see any way of passing options to customise its timer faking. If we could exclude
performance
this issue would go away. p.s. Thanks for the ☕