1 import move from './move';
3 describe('move()', () => {
4 it('should return a new array', () => {
5 const list = [1, 2, 3, 4, 5];
6 expect(move(list, 0, 0) !== list).toBeTruthy();
9 it('should correctly move elements to new positions', () => {
10 const list = [1, 2, 3, 4, 5];
11 expect(move(list, 3, 0)).toEqual([4, 1, 2, 3, 5]);
14 it('should be able to handle negative indices', () => {
15 const list = [1, 2, 3, 4, 5];
16 expect(move(list, -1, 0)).toEqual([5, 1, 2, 3, 4]);
17 expect(move(list, 1, -2)).toEqual([1, 3, 4, 2, 5]);
18 expect(move(list, -3, -4)).toEqual([1, 3, 2, 4, 5]);
23 * This case is arguably an incorrect behaviour of this util, however for the sake
24 * of not altering the public api at this time, I'm adding this test case to test
25 * for regressions in case of a modification / refactor & also because this is the
26 * current contract of this util.
28 it('returns an array with one entry "undefined" if not provided a first argument', () => {
29 expect(move(undefined, 0, 0)).toEqual([undefined]);