Skip to content

Commit 43783cf

Browse files
authored
fix(expect): apply URL equality check only when URL is available (#4670)
1 parent 6e6ee10 commit 43783cf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/expect/src/jest-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function eq(
9696
if (a instanceof Error && b instanceof Error)
9797
return a.message === b.message
9898

99-
if (a instanceof URL && b instanceof URL)
99+
if (typeof URL === 'function' && a instanceof URL && b instanceof URL)
100100
return a.href === b.href
101101

102102
if (Object.is(a, b))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, it } from 'vitest'
2+
3+
// simulate odd environment where URL is monkey-patched or not available
4+
it('jest-expect-no-url', () => {
5+
(globalThis as any).URL = {}
6+
expect('hello').toEqual('hello')
7+
8+
delete (globalThis as any).URL
9+
expect('hello').toEqual('hello')
10+
})

0 commit comments

Comments
 (0)