mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
test(at): add negative indices test (#495)
This commit is contained in:
parent
3c3bba011f
commit
aa92dcf6c8
@ -6,6 +6,11 @@ describe('at', () => {
|
||||
expect(at(['a', 'b', 'c'], [0, 2])).toEqual(['a', 'c']);
|
||||
expect(at(['a', 'b', 'c'], [2, 0])).toEqual(['c', 'a']);
|
||||
});
|
||||
|
||||
it('should support negative indices', () => {
|
||||
expect(at(['a', 'b', 'c'], [-1, -2])).toEqual(['c', 'b']);
|
||||
expect(at(['a', 'b', 'c'], [-2, -1])).toEqual(['b', 'c']);
|
||||
});
|
||||
|
||||
it('should return `undefined` for nonexistent keys', () => {
|
||||
expect(at(['a', 'b', 'c'], [2, 4, 0])).toEqual(['c', undefined, 'a']);
|
||||
@ -13,5 +18,5 @@ describe('at', () => {
|
||||
|
||||
it('should return an empty array when no keys are given', () => {
|
||||
expect(at(['a', 'b', 'c'], [])).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user