diff options
author | 2023-10-16 17:37:14 -0300 | |
---|---|---|
committer | 2023-10-16 15:14:15 -0700 | |
commit | 7becb5ec7457644e5229c03f17c3b99090e6b3c7 (patch) | |
tree | 70a67762d987bb0829d6b6bc02e7d9c68e8d6dda | |
parent | c3f5baa091968e0807724e6fe1d836bbd8a3f115 (diff) | |
download | bun-7becb5ec7457644e5229c03f17c3b99090e6b3c7.tar.gz bun-7becb5ec7457644e5229c03f17c3b99090e6b3c7.tar.zst bun-7becb5ec7457644e5229c03f17c3b99090e6b3c7.zip |
fix(jest): fix toStrictEqual on same URLs (#6528)
Fixes #6492
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 23 | ||||
-rw-r--r-- | test/js/bun/test/expect.test.js | 6 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 2efbde7b0..778ce4bce 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -669,6 +669,7 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2, case JSDOMWrapperType: { if (c2Type == JSDOMWrapperType) { // https://github.com/oven-sh/bun/issues/4089 + // https://github.com/oven-sh/bun/issues/6492 auto* url2 = jsDynamicCast<JSDOMURL*>(v2); auto* url1 = jsDynamicCast<JSDOMURL*>(v1); @@ -677,19 +678,15 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2, if ((url2 == nullptr) != (url1 == nullptr)) { return false; } - - if (url2 && url1) { - return url1->wrapped().href() != url2->wrapped().href(); - } - } else { - if (url2 && url1) { - // toEqual should return false when the URLs' href is not equal - // But you could have added additional properties onto the - // url object itself, so we must check those as well - // But it's definitely not equal if the href() is not the same - if (url1->wrapped().href() != url2->wrapped().href()) { - return false; - } + } + + if (url2 && url1) { + // toEqual or toStrictEqual should return false when the URLs' href is not equal + // But you could have added additional properties onto the + // url object itself, so we must check those as well + // But it's definitely not equal if the href() is not the same + if (url1->wrapped().href() != url2->wrapped().href()) { + return false; } } } diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index 13b549179..1b05c9802 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -977,11 +977,17 @@ describe("expect()", () => { for (let [first, second] of equals) { expect(first).toEqual(second); expect(second).toEqual(first); + + expect(first).toStrictEqual(second); + expect(second).toStrictEqual(first); } for (let [first, second] of not) { expect(first).not.toEqual(second); expect(second).not.toEqual(first); + + expect(first).not.toStrictEqual(second); + expect(second).not.toStrictEqual(first); } expect(Object.fromEntries(Object.entries(new URL("https://example.com")))).not.toStrictEqual( |