1 import replace from './replace';
3 describe('replace()', () => {
4 it('replaces an item from an array', () => {
5 const output = replace(['a', 'b', 'c'], 'b', 'x');
6 expect(output).toEqual(['a', 'x', 'c']);
9 it('replaces only the first occurence should there be multiple', () => {
10 const output = replace(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 'x');
11 expect(output).toEqual(['a', 'x', 'c', 'b', 'd', 'b']);
14 it('returns the original array if the given element does not occur in the input array', () => {
15 const input = ['a', 'b', 'c', 'd'];
16 const output = replace(input, 'e', 'x');
17 expect(output).toBe(input);