sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
806 stars 107 forks source link

Return empty arrays for performance.getEntries, other relevant methods #240

Closed flotwig closed 5 years ago

flotwig commented 5 years ago

Purpose (TL;DR)

Fix issues caused by applications which expect performance.getEntries, performance.getEntriesByName, and performance.getEntriesByType to return arrays (such as Facebook SDK - downstream issue: cypress-io/cypress#3625)

Right now, lolex clobbers these with () => undefined. Just using () => [] instead would fix this.

Background (Problem in detail)

MDN page for Performance functions: https://developer.mozilla.org/en-US/docs/Web/API/Performance

Only 5 have non-undefined return types. The other 2 (besides getEntries.*) are:

Solution

Just have those 3 methods return [] when lolex.install() is called, instead of undefined

benjamingr commented 5 years ago

I can do a release next week when I'm back from DevDays

flotwig commented 5 years ago

@benjamingr Ping, would be awesome to see this released so we can incorporate this fix downstream :)

fatso83 commented 5 years ago

doing it