From 22fab12cf5c8062b127075b0044cfcb37e330c60 Mon Sep 17 00:00:00 2001 From: kleinfreund Date: Tue, 28 Nov 2023 20:21:35 +0100 Subject: [PATCH 1/3] feat(expect): compare URLs by href Change the "equal comparison" logic (as used by `toEqual`, `toStrictEqual`, etc.) to compare `URL` objects by their `href` property. Closes #4614. --- packages/expect/src/jest-utils.ts | 3 +++ test/core/test/jest-expect.test.ts | 6 ++++++ 2 files changed, 9 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..25d640c505fb 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -51,6 +51,12 @@ 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(BigInt(1)).toBeGreaterThan(BigInt(0)) expect(1).toBeGreaterThan(BigInt(0)) expect(BigInt(1)).toBeGreaterThan(0) From 9de94c558549f64c651c73f52adee842cecd1146 Mon Sep 17 00:00:00 2001 From: Philipp Rudloff Date: Wed, 29 Nov 2023 12:47:28 +0100 Subject: [PATCH 2/3] chore(expect): add equality test case for URL with query parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ari Perkkiƶ --- test/core/test/jest-expect.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 25d640c505fb..73489d857d6a 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -56,6 +56,8 @@ describe('jest-expect', () => { 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(BigInt(1)).toBeGreaterThan(BigInt(0)) expect(1).toBeGreaterThan(BigInt(0)) From fd7a2d56bfaf968ff72ab7def109f23f246e6bd6 Mon Sep 17 00:00:00 2001 From: Philipp Rudloff Date: Wed, 29 Nov 2023 13:15:03 +0100 Subject: [PATCH 3/3] chore(expect): expand URL equality test cases --- test/core/test/jest-expect.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 73489d857d6a..4f78f9b8e1cd 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -58,6 +58,10 @@ describe('jest-expect', () => { 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))