mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 19:04:46 +00:00
refactor: change separate tools by category
This commit is contained in:
23
core/stdlib/src/arrays/last/index.test.ts
Normal file
23
core/stdlib/src/arrays/last/index.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { last } from '.';
|
||||
|
||||
describe('last', () => {
|
||||
it('return the last element of a non-empty array', () => {
|
||||
expect(last([1, 2, 3, 4, 5])).toBe(5);
|
||||
expect(last(['a', 'b', 'c'])).toBe('c');
|
||||
});
|
||||
|
||||
it('return undefined if the array is empty and no default value is provided', () => {
|
||||
expect(last([])).toBeUndefined();
|
||||
});
|
||||
|
||||
it('return the default value for an empty array with a default value', () => {
|
||||
expect(last([], 42)).toBe(42);
|
||||
expect(last([], 'default')).toBe('default');
|
||||
});
|
||||
|
||||
it('return the first element even if a default value is provided', () => {
|
||||
expect(last([1, 2, 3], 42)).toBe(3);
|
||||
expect(last(['a', 'b', 'c'], 'default')).toBe('c');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user