/
delete.test.js
85 lines (79 loc) · 2 KB
/
delete.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'babel-polyfill'
import { delete as _delete } from '../'
import { withHintSameType, withMultipleTypeInputs } from './recompose'
import { immutableTest } from './tests'
import { indexed, keyed } from './types'
import { compose, runTests, setupTest } from './util'
const enhance = compose(
withMultipleTypeInputs,
withHintSameType
)
const testDelete = enhance(immutableTest(({ data, path }) => _delete(data, path)))
describe('delete', function() {
const context = setupTest()
const { Symbol } = context
const symbolA = Symbol('a')
const tests = {
'should delete indexed `data` on `path`': {
inputs: {
data: {
value: ['a', 'b', 'c'],
types: indexed()
},
path: {
value: 1
}
},
expected: ['a', 'c']
},
'should delete keyed `data` on `path`': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c':3 },
types: keyed()
},
path: {
value: 'c'
}
},
expected: { 'a':1, 'b':2 }
},
'should delete deep `data` on `path` with nested object': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c': { 'd': 3, 'e': 4 } },
types: keyed()
},
path: {
value: 'c.d'
}
},
expected: { 'a':1, 'b':2, 'c': { 'e': 4 } }
},
'should delete deep `data` on `path` with nested array': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c': [3, 4, 5] },
types: keyed()
},
path: {
value: 'c.1'
}
},
expected: { 'a':1, 'b':2, 'c': [3, 5] }
},
'should delete keyed `data` with symbol `path`': {
inputs: {
data: {
value: { [symbolA]:1, 'b':2, 'c':3 }
//types: keyed() //TODO BRN: immutable types do not seem to be working with symbols
},
path: {
value: symbolA
}
},
expected: { 'b':2, 'c':3 }
}
}
runTests(tests, context, testDelete)
})