Skip to content

Commit

Permalink
fix: dates are equal, if both are invalid (#2326)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 14, 2022
1 parent a57914f commit 30c59f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/chai/jest-utils.ts
Expand Up @@ -125,8 +125,8 @@ function eq(
case '[object Date]':
// Coerce dates to numeric primitive values. Dates are compared by their
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
return +a === +b
// of `NaN` are equivalent.
return (isNaN(a) && isNaN(b)) || (+a === +b)
// RegExps are compared by their source patterns and flags.
case '[object RegExp]':
return a.source === b.source && a.flags === b.flags
Expand Down
3 changes: 3 additions & 0 deletions test/core/test/jest-expect.test.ts
Expand Up @@ -35,6 +35,9 @@ describe('jest-expect', () => {
expect([{ text: 'Bye' }]).not.toContainEqual({ text: 'Hello' })
expect(1).toBeGreaterThan(0)

expect(new Date(0)).toEqual(new Date(0))
expect(new Date('inValId')).toEqual(new Date('inValId'))

expect(BigInt(1)).toBeGreaterThan(BigInt(0))
expect(1).toBeGreaterThan(BigInt(0))
expect(BigInt(1)).toBeGreaterThan(0)
Expand Down

0 comments on commit 30c59f5

Please sign in to comment.