vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Ability to set locale

Open GideonMax opened this issue 3 years ago • 1 comments

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

GideonMax avatar Sep 21 '22 14:09 GideonMax

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 avatar Sep 21 '22 15:09 sheremet-va

@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

GideonMax avatar Sep 29 '22 14:09 GideonMax

it seems to work, closing issue

GideonMax avatar Oct 02 '22 05:10 GideonMax