diff options
author | 2023-04-06 14:49:07 -0700 | |
---|---|---|
committer | 2023-04-06 14:49:07 -0700 | |
commit | 2b170c9d135930f80fa86dc2f92120a70c2720d9 (patch) | |
tree | e1a47e325df71a08fd936e2c0603684101f6269e /test/js | |
parent | 1d138057cb861fe540cfe5ef49905225cee40ae8 (diff) | |
download | bun-2b170c9d135930f80fa86dc2f92120a70c2720d9.tar.gz bun-2b170c9d135930f80fa86dc2f92120a70c2720d9.tar.zst bun-2b170c9d135930f80fa86dc2f92120a70c2720d9.zip |
Fix `toEqual` when the second array has extra array holes (#2580)
* iterate through remaining indexes, keep prop identifier
* tests
* format
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/test/test-test.test.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/js/bun/test/test-test.test.ts b/test/js/bun/test/test-test.test.ts index 2777b35fa..5154950de 100644 --- a/test/js/bun/test/test-test.test.ts +++ b/test/js/bun/test/test-test.test.ts @@ -777,8 +777,57 @@ test("deepEquals - symbols", () => { expect(o).toEqual(k); }); +test("deepEquals should not segfault", () => { + const obj = { ...Object.fromEntries(Object.entries([1, 2, 3, 4])), length: 4 }; + expect(() => { + expect(obj).toEqual([1, 2, 3, 4]); + }).toThrow(); + expect(() => { + expect([1, 2, 3, 4]).toEqual(obj); + }).toThrow(); +}); + test("toEqual objects and arrays", () => { { + let obj = { 0: 4, 1: 3, length: 2 }; + expect(Array.from(obj)).toEqual([4, 3]); + expect(Array.from(obj)).toStrictEqual([4, 3]); + } + { + let obj = { 0: 4, 1: 3, length: 4 }; + expect(Array.from(obj)).toEqual([4, 3]); + expect(Array.from(obj)).not.toStrictEqual([4, 3]); + expect(Array.from(obj)).toEqual([4, 3, undefined, undefined]); + expect(Array.from(obj)).toStrictEqual([4, 3, undefined, undefined]); + expect(Array.from(obj)).toEqual([4, 3, , ,]); + expect(Array.from(obj)).not.toStrictEqual([4, 3, , ,]); + } + { + let a1 = [1, undefined, 3, , 4, null]; + let a2 = [1, undefined, 3, , 4, null, , ,]; + expect(a1).toEqual(a2); + expect(a1).not.toStrictEqual(a2); + expect(a2).toEqual(a1); + expect(a2).not.toStrictEqual(a1); + } + { + let a1 = [, , , , , , , , , , , ,]; + let a2 = [undefined]; + expect(a1).toEqual(a2); + expect(a1).not.toStrictEqual(a2); + expect(a2).toEqual(a1); + expect(a2).not.toStrictEqual(a1); + } + { + const a = [1]; + const b = [1]; + expect(a).toEqual(b); + Object.preventExtensions(b); + expect(a).toEqual(b); + Object.preventExtensions(a); + expect(a).toEqual(b); + } + { let o1 = { 1: 4, 6: 3 }; let o2 = { 1: 4, 6: 3 }; expect(o1).toEqual(o2); |