@repobuddy/vitest/setup/browser
@repobuddy/vitest/setup/browser makes Intl.DateTimeFormat().resolvedOptions().timeZone report GMT in browser
tests.
browserTestPreset() adds it to test.setupFiles for you. Add it yourself only in a browser config that does not use
the preset:
export default defineConfig({ test: { setupFiles: ['@repobuddy/vitest/setup/browser'] },})Options
Section titled “Options”None. The file exports nothing.
What it does
Section titled “What it does”- Before the tests in each file (
beforeAll), it spies onIntl.DateTimeFormat.prototype.resolvedOptionsand returns the original options withtimeZone: 'GMT'. - After the tests in each file (
afterAll), it callsvi.restoreAllMocks().
Behavior
Section titled “Behavior”- It changes only what
resolvedOptions()returns. It does not change the time zone the browser uses to format dates. vi.restoreAllMocks()inafterAllalso restores spies your own tests left in place at the end of the file.- In Node.js,
nodeTestPreset()setsprocess.env.TZinstead.
Examples
Section titled “Examples”// a.spec.tsx, run by browserTestPreset()it('reports GMT', () => { expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe('GMT')})