From d8e94d8f10367d165d15904f7c7a31165842f9ec Mon Sep 17 00:00:00 2001 From: Almeida Date: Sat, 6 Jul 2024 21:32:01 +0100 Subject: [PATCH] test: complete collection coverage (#10380) --- packages/collection/__tests__/collection.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/collection/__tests__/collection.test.ts b/packages/collection/__tests__/collection.test.ts index fd538aca5..e0073ac07 100644 --- a/packages/collection/__tests__/collection.test.ts +++ b/packages/collection/__tests__/collection.test.ts @@ -138,6 +138,12 @@ describe('each() tests', () => { expectInvalidFunctionError(() => coll.each(123), 123); }); + test('binds the thisArg', () => { + coll.each(function each() { + expect(this).toBeNull(); + }, null); + }); + test('iterate over each item', () => { const coll = createTestCollection(); const a: [string, number][] = []; @@ -964,6 +970,10 @@ describe('findLast() tests', () => { expect(coll.findLast((value) => value % 2 === 1)).toStrictEqual(3); }); + test('returns undefined if no item matches', () => { + expect(coll.findLast((value) => value === 10)).toBeUndefined(); + }); + test('throws if fn is not a function', () => { // @ts-expect-error: Invalid function expectInvalidFunctionError(() => createCollection().findLast()); @@ -985,6 +995,10 @@ describe('findLastKey() tests', () => { expect(coll.findLastKey((value) => value % 2 === 1)).toStrictEqual('c'); }); + test('returns undefined if no item matches', () => { + expect(coll.findLastKey((value) => value === 10)).toBeUndefined(); + }); + test('throws if fn is not a function', () => { // @ts-expect-error: Invalid function expectInvalidFunctionError(() => createCollection().findLastKey());