test: complete collection coverage (#10380)

This commit is contained in:
Almeida
2024-07-06 21:32:01 +01:00
committed by Vlad Frangu
parent 9779baea84
commit c1b5242d2f

View File

@@ -138,6 +138,12 @@ describe('each() tests', () => {
expectInvalidFunctionError(() => coll.each(123), 123); expectInvalidFunctionError(() => coll.each(123), 123);
}); });
test('binds the thisArg', () => {
coll.each(function each() {
expect(this).toBeNull();
}, null);
});
test('iterate over each item', () => { test('iterate over each item', () => {
const coll = createTestCollection(); const coll = createTestCollection();
const a: [string, number][] = []; const a: [string, number][] = [];
@@ -964,6 +970,10 @@ describe('findLast() tests', () => {
expect(coll.findLast((value) => value % 2 === 1)).toStrictEqual(3); 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', () => { test('throws if fn is not a function', () => {
// @ts-expect-error: Invalid function // @ts-expect-error: Invalid function
expectInvalidFunctionError(() => createCollection().findLast()); expectInvalidFunctionError(() => createCollection().findLast());
@@ -985,6 +995,10 @@ describe('findLastKey() tests', () => {
expect(coll.findLastKey((value) => value % 2 === 1)).toStrictEqual('c'); 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', () => { test('throws if fn is not a function', () => {
// @ts-expect-error: Invalid function // @ts-expect-error: Invalid function
expectInvalidFunctionError(() => createCollection().findLastKey()); expectInvalidFunctionError(() => createCollection().findLastKey());