vitest
vitest copied to clipboard
Ability to set locale
Clear and concise description of the problem
Some components in my app use locale dependent functions (like Date.toLocaleString()). While I want users to experience dates in a locale appropriate format, I don't want my snapshot tests to fail when someone on the team has a different locale, and I don't want to force a consistent locale on my devs.
Suggested solution
have a vi.mockLocales that will mock all locale dependent functions with a default locale that isn't system dependent.
Alternative
set the environment's locale either through the engine (jsdom/happy-dom) or through the operating system in a way that preserves the previous Locale
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
I don't think it's possible to do programatically. Date is really hard to work with in Node. But you can change locale with LC_ALL env:
LC_ALL=en_US.UTF-8 vitest
This might not work on some systems. You can also try these envs: LANG, LANGUAGE, LC_ALL, LC_MESSAGES
@sheremet-va I set the locale to the c locale and it seems to work, I'll do further tests and then close the issue if that seems to solve it
it seems to work, closing issue