replaceAtArrayIndex.spec.tsx 706 B

1234567891011121314151617181920212223
  1. import {replaceAtArrayIndex} from 'sentry/utils/replaceAtArrayIndex';
  2. describe('utils/replaceAtArrayIndex', function () {
  3. it('replaces simple value at index', function () {
  4. const arr = [1, 2, 3];
  5. expect(replaceAtArrayIndex(arr, 1, 40)).toEqual([1, 40, 3]);
  6. });
  7. it('does not mutate array', function () {
  8. const arr = [1, 2, 3];
  9. expect(replaceAtArrayIndex(arr, 0, 40)).toEqual([40, 2, 3]);
  10. expect(arr).toEqual([1, 2, 3]);
  11. });
  12. it('replaces at boundaries of array', function () {
  13. const arr = [1, 2, 3];
  14. expect(replaceAtArrayIndex(arr, 0, 40)).toEqual([40, 2, 3]);
  15. const arr2 = [1, 2, 3];
  16. expect(replaceAtArrayIndex(arr2, 2, 40)).toEqual([1, 2, 40]);
  17. });
  18. });