fake-timers: window.performance.mark becomes undefined after timer install

I have noticed the following behavior in the browser:

import { useFakeTimers } from 'sinon';

console.log('1', window.performance.mark) // '1', function mark() { ... }
clock = useFakeTimers();
console.log('2', window.performance.mark) // '2', undefined

window.performance became a function after calling useFakeTimers. I believe that the issue is coming from this line: https://github.com/sinonjs/lolex/blob/c08ff362a47e9786bc62da6c37175838bb7bd21e/src/lolex-src.js#L406-L408

One simple workaround is the following:

-clock = useFakeTimers();
+clock = useFakeTimers({
+  toFake: ["setTimeout", "clearTimeout", "setImmediate", "clearImmediate","setInterval", + "clearInterval", "Date"]
+});

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 15
  • Comments: 25 (13 by maintainers)

Commits related to this issue

Most upvoted comments

sorry, completely forgot about it - can take a look early next week

As a temporary solution, I used the following function:

function useFakeTimers() {
    const timer = sinon.useFakeTimers();
    performance.mark = () => void 0;
    performance.clearMarks = () => void 0;
    performance.measure = () => void 0;
    performance.clearMeasures = () => void 0;
}

const timer = useFakeTimers();

It works with:

  • react@16.2.0
  • sinon@4.2.0
  • enzyme-adapter-react-16@1.1.1
  • enzyme@3.3.0

Ok, I’m gonna make a patch soon!

@fatso83 I still can’t assign myself to issues by the way 😄 I’ll take a stab next week hopefully