Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Date() instance of Date should be true when using setSystemTime #4579

Closed
6 tasks done
spiroka opened this issue Nov 23, 2023 · 1 comment · Fixed by #4584
Closed
6 tasks done

new Date() instance of Date should be true when using setSystemTime #4579

spiroka opened this issue Nov 23, 2023 · 1 comment · Fixed by #4584
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@spiroka
Copy link
Contributor

spiroka commented Nov 23, 2023

Describe the bug

When using setSystemTime, Date objects will not be instances of (the now mocked) Date.

Reproduction

https://stackblitz.com/edit/vitejs-vite-uwiefu?file=index.test.js

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
    Memory: 10.69 GB / 32.00 GB

  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD

  Browsers:
    Edge: Spartan (44.19041.3570.0), Chromium (119.0.2151.72)
    Internet Explorer: 11.0.19041.3570

  npmPackages:
    @vitejs/plugin-react: ^4.1.1 => 4.1.1
    @vitest/coverage-v8: ^0.34.6 => 0.34.6
    @vitest/ui: ^0.34.6 => 0.34.6
    vite: 4.5.0 => 4.5.0
    vitest: ^0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Nov 23, 2023
@sheremet-va
Copy link
Member

Workaround:

vi.useFakeTimers()
vi.setSystemTime('2023-11-22');
expect(new Date()).toBeInstanceOf(Date);

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants