Skip to content

Commit

Permalink
🚚 Move tests in apply's own test file
Browse files Browse the repository at this point in the history
  • Loading branch information
nlepage committed Nov 12, 2017
1 parent 5d04522 commit 794ff6c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
57 changes: 56 additions & 1 deletion src/core/apply.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
)
})

})
38 changes: 0 additions & 38 deletions src/core/set.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 794ff6c

Please sign in to comment.