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

feat(expect): compare URL objects by href #4615

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/expect/src/jest-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ function eq(
if (a instanceof Error && b instanceof Error)
return a.message === b.message

if (a instanceof URL && b instanceof URL)
return a.href === b.href

if (Object.is(a, b))
return true

Expand Down
6 changes: 6 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ describe('jest-expect', () => {
expect(new Date(0)).toEqual(new Date(0))
expect(new Date('inValId')).toEqual(new Date('inValId'))

expect(new Error('message')).toEqual(new Error('message'))
expect(new Error('message')).not.toEqual(new Error('different message'))
kleinfreund marked this conversation as resolved.
Show resolved Hide resolved

expect(new URL('https://example.org')).toEqual(new URL('https://example.org'))
expect(new URL('https://example.org')).not.toEqual(new URL('https://different-example.org'))

kleinfreund marked this conversation as resolved.
Show resolved Hide resolved
expect(BigInt(1)).toBeGreaterThan(BigInt(0))
expect(1).toBeGreaterThan(BigInt(0))
expect(BigInt(1)).toBeGreaterThan(0)
Expand Down
Loading