diff options
author | 2023-09-18 17:59:09 +0800 | |
---|---|---|
committer | 2023-09-18 02:59:09 -0700 | |
commit | c7de270bbba05e0fc850290b27d617bda1df2206 (patch) | |
tree | 955759fa7a7d4211a11938cec5e8ca7dff65e52c /test | |
parent | c66d4a724b675c6ebbd64ccf98e1ce9933f2ef00 (diff) | |
download | bun-c7de270bbba05e0fc850290b27d617bda1df2206.tar.gz bun-c7de270bbba05e0fc850290b27d617bda1df2206.tar.zst bun-c7de270bbba05e0fc850290b27d617bda1df2206.zip |
feat(test): Implement `arrayContaining` (#5572)
* feat(test): implement `arrayContaining`
* feat: early return when expectedArray is empty
* feat: add test for toEqual
* chore: use `JSC::isArray`
* chore: use getIndex for performance
* fix: use deepEqual
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/js/bun/test/expect.test.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index 804a5339f..4b9e5ec22 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -1298,6 +1298,16 @@ describe("expect()", () => { a = { a: 1, b: 2, c: 3 }; b = { a: 1, b: 2 }; expect(a).not.toEqual(b); + + array1 = [1, 2, 3]; + expect(array1).toEqual(expect.arrayContaining([])); + expect(array1).toEqual(expect.arrayContaining([1, 2])); + expect(array1).not.toEqual(expect.arrayContaining([1, 2, 4])); + + array2 = [{ a: 1, b: 2 }, { a: { a: 1 } }]; + expect(array2).toEqual(expect.arrayContaining([{ a: 1, b: 2 }])); + expect(array2).toEqual(expect.arrayContaining([{ a: { a: 1 } }])); + expect(array2).not.toEqual(expect.arrayContaining([{ a: 2, b: 3 }])); }); test("symbol based keys in arrays are processed correctly", () => { @@ -2624,6 +2634,12 @@ describe("expect()", () => { expect({ a: [1, 2, 3] }).toMatchObject({ a: [1, 2, 3] }); expect({ a: [1, 2, 4] }).not.toMatchObject({ a: [1, 2, 3] }); + expect({ a: [1, 2, 3] }).toMatchObject({ a: expect.arrayContaining([1, 2]) }); + expect({ a: [1, 2, 3] }).not.toMatchObject({ a: expect.arrayContaining([4]) }); + expect({ a: ['hello', 'world'] }).toMatchObject({ a: expect.arrayContaining([]) }); + expect({ a: ['hello', 'world'] }).toMatchObject({ a: expect.arrayContaining(['world']) }); + expect({ a: ['hello', 'world'] }).not.toMatchObject({ a: expect.arrayContaining(['hello', 'mars']) }); + expect([]).toMatchObject([]); expect([]).toMatchObject({}); expect({}).not.toMatchObject([]); |