import { cleanup } from '@testing-library/react'; import { arrayIsEmpty, arrayMove } from '.'; afterEach(cleanup); describe('Check "utils/common/array"', () => { describe('arrayIsEmpty', () => { it('check with empty arrays', () => { expect(arrayIsEmpty([])).toBeTruthy(); expect(arrayIsEmpty([false])).toBeTruthy(); expect(arrayIsEmpty([null])).toBeTruthy(); expect(arrayIsEmpty([undefined])).toBeTruthy(); expect(arrayIsEmpty([NaN])).toBeTruthy(); }); it('check with non-empty arrays', () => { expect(arrayIsEmpty([0])).toBeFalsy(); expect(arrayIsEmpty([''])).toBeFalsy(); expect(arrayIsEmpty([[]])).toBeFalsy(); expect(arrayIsEmpty([{}])).toBeFalsy(); expect(arrayIsEmpty([() => false])).toBeFalsy(); }); }); const item1 = 1; const item2 = 2; const item3 = 3; const array = [item1, item2, item3]; describe('arrayMove', () => { it('check switch array items indexes', () => { const newArray = arrayMove(array, 0, 2); expect(newArray[2]).toBe(item1); expect(newArray[0]).toBe(item2); }); it('check with the negative indexes', () => { const newArray = arrayMove(array, -3, -1); expect(newArray[2]).toBe(item1); expect(newArray[0]).toBe(item2); }); }); });