|
| 1 | +import removeBatch from './removeBatch' |
| 2 | + |
| 3 | +describe('merge', () => { |
| 4 | + const getOp = value => { |
| 5 | + const changeValue = jest.fn() |
| 6 | + removeBatch(['foo', value], {}, { changeValue }) |
| 7 | + return changeValue.mock.calls[0][2] |
| 8 | + } |
| 9 | + |
| 10 | + it('should call changeValue once', () => { |
| 11 | + const changeValue = jest.fn() |
| 12 | + const state = {} |
| 13 | + const result = removeBatch(['foo', [1, 2]], state, { changeValue }) |
| 14 | + expect(result).toBeUndefined() |
| 15 | + expect(changeValue).toHaveBeenCalled() |
| 16 | + expect(changeValue).toHaveBeenCalledTimes(1) |
| 17 | + expect(changeValue.mock.calls[0][0]).toBe(state) |
| 18 | + expect(changeValue.mock.calls[0][1]).toBe('foo') |
| 19 | + expect(typeof changeValue.mock.calls[0][2]).toBe('function') |
| 20 | + }) |
| 21 | + |
| 22 | + it('should return undefined if array is undefined', () => { |
| 23 | + const op = getOp([0, 1]) |
| 24 | + const result = op(undefined) |
| 25 | + expect(result).toBeUndefined() |
| 26 | + }) |
| 27 | + |
| 28 | + it('should return the original array if no indexes are specified to be removed', () => { |
| 29 | + const op = getOp([]) |
| 30 | + const result = op(['a', 'b', 'c', 'd', 'e']) |
| 31 | + expect(Array.isArray(result)).toBe(true) |
| 32 | + expect(result).toEqual(['a', 'b', 'c', 'd', 'e']) |
| 33 | + }) |
| 34 | + |
| 35 | + it('should remove the values at the specified indexes', () => { |
| 36 | + const op = getOp([1, 3]) |
| 37 | + const result = op(['a', 'b', 'c', 'd', 'e']) |
| 38 | + expect(Array.isArray(result)).toBe(true) |
| 39 | + expect(result).toEqual(['a', 'c', 'e']) |
| 40 | + }) |
| 41 | +}) |
0 commit comments