UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

16 lines (13 loc) 521 B
import { swapItems } from './swapItems'; describe('swapItems', () => { test('should swap two items in a list but not modify the original list', () => { const list = [1, 2, 3, 4, 5]; const updatedList = swapItems(list, 2, 4); expect(updatedList).toEqual([1, 2, 5, 4, 3]); expect(list).toEqual([1, 2, 3, 4, 5]); }); test('should throw an error if the index is out of bounds', () => { const list = [1, 2, 3, 4, 5]; expect(() => swapItems(list, 2, 5)).toThrowError('Invalid index'); }); });