Skip to content

Changes to debounce() causing test failures with mocked timers #2918

@ilikesleeping

Description

@ilikesleeping

In v1.12.1, it seems the debounce method has changed to use now(), which holds onto a reference to whatever Date.now was when underscore was loaded the first time.

This has caused problems in our jest tests, where we're using jest.useFakeTimers to mock changes in time to test timeouts and suchlike, because any mocked changes to the date functions won't have any effect.

Looking at the tests added at the same time, it seems this was perhaps intentional? If so, I think it's possibly not a suitable change for a .1 patch release, as it'll break anything that was relying on mocking the current time - which I suspect is a reasonably common use case in tests. (Ok, maybe not that common, but not totally out there...)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions