Skip to content

Commit

Permalink
fix(expect): apply URL equality check only when URL is available (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 5, 2023
1 parent 6e6ee10 commit 43783cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/expect/src/jest-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function eq(
if (a instanceof Error && b instanceof Error)
return a.message === b.message

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

if (Object.is(a, b))
Expand Down
10 changes: 10 additions & 0 deletions test/core/test/jest-expect-no-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, it } from 'vitest'

// simulate odd environment where URL is monkey-patched or not available
it('jest-expect-no-url', () => {
(globalThis as any).URL = {}
expect('hello').toEqual('hello')

delete (globalThis as any).URL
expect('hello').toEqual('hello')
})

0 comments on commit 43783cf

Please sign in to comment.