From f7a73338a552e5479a0f383cba8f761351552201 Mon Sep 17 00:00:00 2001 From: Philipp Rudloff Date: Wed, 29 Nov 2023 14:31:18 +0100 Subject: [PATCH] feat(expect): compare URL objects by href (#4615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ari Perkkiƶ --- packages/expect/src/jest-utils.ts | 3 +++ test/core/test/jest-expect.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/expect/src/jest-utils.ts b/packages/expect/src/jest-utils.ts index fa9206bcbfd2..63aa295b5a20 100644 --- a/packages/expect/src/jest-utils.ts +++ b/packages/expect/src/jest-utils.ts @@ -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 diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 1e92701e2055..4f78f9b8e1cd 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -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)