1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

refactor: change separate tools by category

This commit is contained in:
2025-05-19 17:43:42 +07:00
parent d55737df2f
commit 78fb4da82a
158 changed files with 32 additions and 24 deletions

View File

@@ -0,0 +1,23 @@
import { describe, it, expect } from 'vitest';
import { first } from '.';
describe('first', () => {
it('return the first element of a non-empty array', () => {
expect(first([1, 2, 3])).toBe(1);
expect(first(['a', 'b', 'c'])).toBe('a');
});
it('return undefined for an empty array without a default value', () => {
expect(first([])).toBeUndefined();
});
it('return the default value for an empty array with a default value', () => {
expect(first([], 42)).toBe(42);
expect(first([], 'default')).toBe('default');
});
it('return the first element even if a default value is provided', () => {
expect(first([1, 2, 3], 42)).toBe(1);
expect(first(['a', 'b', 'c'], 'default')).toBe('a');
});
});