|
1 | 1 | import type { Tester } from '@vitest/expect'
|
2 | 2 | import { getCurrentTest } from '@vitest/runner'
|
| 3 | +import { Temporal } from 'temporal-polyfill' |
3 | 4 | import { describe, expect, expectTypeOf, test, vi } from 'vitest'
|
4 | 5 |
|
5 | 6 | describe('expect.soft', () => {
|
@@ -346,3 +347,45 @@ describe('iterator', () => {
|
346 | 347 | expect(a).not.toStrictEqual(b)
|
347 | 348 | })
|
348 | 349 | })
|
| 350 | + |
| 351 | +describe('Temporal equality', () => { |
| 352 | + describe.each([ |
| 353 | + ['Instant', ['2025-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z']], |
| 354 | + ['ZonedDateTime', ['2025-01-01T00:00:00+01:00[Europe/Amsterdam]', '2025-01-01T00:00:00+01:00[Europe/Paris]']], |
| 355 | + ['PlainDateTime', ['2025-01-01T00:00:00.000', '2026-01-01T00:00:00.000']], |
| 356 | + ['PlainDate', ['2025-01-01', '2026-01-01']], |
| 357 | + ['PlainTime', ['15:00:00.000', '16:00:00.000']], |
| 358 | + ['PlainYearMonth', ['2025-01', '2026-01']], |
| 359 | + ['PlainMonthDay', ['01-01', '02-01']], |
| 360 | + ] as const)('of $className', (className, [first, second]) => { |
| 361 | + test('returns true when equal', () => { |
| 362 | + const a = Temporal[className].from(first) |
| 363 | + const b = Temporal[className].from(first) |
| 364 | + |
| 365 | + expect(a).toStrictEqual(b) |
| 366 | + }) |
| 367 | + |
| 368 | + test('returns false when not equal', () => { |
| 369 | + const a = Temporal[className].from(first) |
| 370 | + const b = Temporal[className].from(second) |
| 371 | + |
| 372 | + expect(a).not.toStrictEqual(b) |
| 373 | + }) |
| 374 | + }) |
| 375 | + |
| 376 | + describe('of Duration', () => { |
| 377 | + test('returns true when .toString() is equal', () => { |
| 378 | + const a = Temporal.Duration.from('P1M') |
| 379 | + const b = Temporal.Duration.from('P1M') |
| 380 | + |
| 381 | + expect(a).toStrictEqual(b) |
| 382 | + }) |
| 383 | + |
| 384 | + test('returns true when .toString() is not equal', () => { |
| 385 | + const a = Temporal.Duration.from('PT1M') |
| 386 | + const b = Temporal.Duration.from('PT60S') |
| 387 | + |
| 388 | + expect(a).not.toStrictEqual(b) |
| 389 | + }) |
| 390 | + }) |
| 391 | +}) |
0 commit comments