time-zone.client.spec.ts 792 B

123456789101112131415161718192021222324
  1. import { afterEach, describe, expect, it, vi } from 'vitest'
  2. import { resolvedClientTimeZone } from '../src/client/time-zone.ts'
  3. afterEach(() => {
  4. vi.restoreAllMocks()
  5. })
  6. describe('Session Controller browser time zone', () => {
  7. it('returns the runtime-resolved zone', () => {
  8. expect(resolvedClientTimeZone()).toBe(
  9. new Intl.DateTimeFormat().resolvedOptions().timeZone,
  10. )
  11. })
  12. it.each([undefined, ''])('fails loud when the runtime exposes no zone %#', (timeZone) => {
  13. const options = new Intl.DateTimeFormat().resolvedOptions()
  14. vi.spyOn(Intl.DateTimeFormat.prototype, 'resolvedOptions').mockReturnValue({
  15. ...options,
  16. timeZone: timeZone as string,
  17. })
  18. expect(() => resolvedClientTimeZone()).toThrow('browser time zone is unavailable')
  19. })
  20. })