diff --git a/packages/expect/src/jest-utils.ts b/packages/expect/src/jest-utils.ts index 63aa295b5a20..a6d842043ae1 100644 --- a/packages/expect/src/jest-utils.ts +++ b/packages/expect/src/jest-utils.ts @@ -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)) diff --git a/test/core/test/jest-expect-no-url.test.ts b/test/core/test/jest-expect-no-url.test.ts new file mode 100644 index 000000000000..6f5ae6ce3211 --- /dev/null +++ b/test/core/test/jest-expect-no-url.test.ts @@ -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') +})