diff --git a/src/core/apply.spec.js b/src/core/apply.spec.js index dd43edc4..0fffc567 100644 --- a/src/core/apply.spec.js +++ b/src/core/apply.spec.js @@ -12,7 +12,7 @@ describe('Apply', () => { const inc = (obj, path, ...args) => apply(obj, path, (obj, prop) => { obj[prop] = _inc(obj[prop], ...args) }) - it('should inc in all an array', () => { + it('should inc in an array slice', () => { immutaTest( input => { const output = inc(input, 'nested.prop[:].val', 2) @@ -49,5 +49,60 @@ describe('Apply', () => { 'nested.prop.2.val', 'nested.prop.3.val', ) + + immutaTest( + input => { + const output = inc(input, 'nested.prop[1:3].val') + expect(output).toEqual({ + nested: { + prop: [{ val: 0 }, { + val: 2, + other: {}, + }, { val: 3 }, { val: 3 }], + }, + other: {}, + }) + return output + }, + { + nested: { + prop: [{ val: 0 }, { + val: 1, + other: {}, + }, { val: 2 }, { val: 3 }], + }, + other: {}, + }, + 'nested.prop.1.val', + 'nested.prop.2.val', + ) + + immutaTest( + input => { + const output = inc(input, 'nested.prop[-3:-1].val') + expect(output).toEqual({ + nested: { + prop: [{ val: 0 }, { + val: 2, + other: {}, + }, { val: 3 }, { val: 3 }], + }, + other: {}, + }) + return output + }, + { + nested: { + prop: [{ val: 0 }, { + val: 1, + other: {}, + }, { val: 2 }, { val: 3 }], + }, + other: {}, + }, + 'nested.prop.1.val', + 'nested.prop.2.val', + ) }) + }) diff --git a/src/core/set.spec.js b/src/core/set.spec.js index d84945c5..43bbca60 100644 --- a/src/core/set.spec.js +++ b/src/core/set.spec.js @@ -31,44 +31,6 @@ describe('Set', () => { }, 'nested.prop.0') }) - it('should set values in an array slice', () => { - immutaTest(input => { - const output = set(input, 'nested.prop[:]', 'final') - expect(output).toEqual({ - nested: { prop: ['final', 'final', 'final'] }, - other: {}, - }) - return output - }, { - nested: { prop: ['a', 'b', 'c'] }, - other: {}, - }, 'nested.prop') - - immutaTest(input => { - const output = set(input, 'nested.prop[1:3].val', 'final') - expect(output).toEqual({ - nested: { prop: [{ val: 'a' }, { val: 'final' }, { val: 'final' }, { val: 'd' }] }, - other: {}, - }) - return output - }, { - nested: { prop: [{ val: 'a' }, { val: 'b' }, { val: 'c' }, { val: 'd' }] }, - other: {}, - }, 'nested.prop') - - immutaTest(input => { - const output = set(input, 'nested.prop[-3:-1].val', 'final') - expect(output).toEqual({ - nested: { prop: [{ val: 'a' }, { val: 'final' }, { val: 'final' }, { val: 'd' }] }, - other: {}, - }) - return output - }, { - nested: { prop: [{ val: 'a' }, { val: 'b' }, { val: 'c' }, { val: 'd' }] }, - other: {}, - }, 'nested.prop') - }) - it('should set a deep undefined prop', () => { immutaTest((input, path) => { const output = set(input, path, 'final')