Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dates are equal, if both are invalid #2326

Merged
merged 1 commit into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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