-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Description
Bug report
Describe the bug
Upgrading nextJS from 7.0.2 to the latest version of next 8.0.4 break tests that rely on mocking Date.now(). These tests are written in files that do not import nextjs
To Reproduce
Clone sample repo: https://github.com/ssylvia/next-test-date-mock
NextJS Update Breaks Date Mocks
Steps to reproduce:
yarn install- Run
yarn test --no-cache. - Notice that all test pass
- Upgrade to nextjs 8
- Run
yarn test --no-cache. - See failing tests because
Datemock no longer works
Test that fails
Source method (src/utils/index.ts)
export const getCurrentTime = () => {
const time = Date.now();
return time;
};Test (src/utils/index.ts)
test("getCurrentTime", () => {
jest.spyOn(Date, "now").mockImplementation(() => 0);
expect(getCurrentTime()).toBe(0);
});Expected behavior
Date.now() should continue to be mocked
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: MacOS
- Version of Next.js: 8.0.4
- Node: v10.13.0
rmoedt and michaeljonathanblack
Metadata
Metadata
Assignees
Labels
No labels