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(expect): apply URL equality check only when URL is available #4670

Merged
merged 3 commits into from
Dec 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
Loading