Skip to content

Commit

Permalink
feat(expect): compare URL objects by href (#4615)
Browse files Browse the repository at this point in the history
Co-authored-by: Ari Perkkiö <[email protected]>
  • Loading branch information
kleinfreund and AriPerkkio authored Nov 29, 2023
1 parent ec3d694 commit f7a7333
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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
12 changes: 12 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,18 @@ 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'))

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'))
expect(new URL('https://example.org?query=value')).toEqual(new URL('https://example.org?query=value'))
expect(new URL('https://example.org?query=one')).not.toEqual(new URL('https://example.org?query=two'))
expect(new URL('https://subdomain.example.org/path?query=value#fragment-identifier')).toEqual(new URL('https://subdomain.example.org/path?query=value#fragment-identifier'))
expect(new URL('https://subdomain.example.org/path?query=value#fragment-identifier')).not.toEqual(new URL('https://subdomain.example.org/path?query=value#different-fragment-identifier'))
expect(new URL('https://example.org/path')).toEqual(new URL('/path', 'https://example.org'))
expect(new URL('https://example.org/path')).not.toEqual(new URL('/path', 'https://example.com'))

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

0 comments on commit f7a7333

Please sign in to comment.