-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_test.js
43 lines (38 loc) · 973 Bytes
/
update_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
module.exports = {
plugin: require('./update'),
setup: setup,
}
function setup(store) {
test('update', function() {
store.set('foo', { cat:'mat' })
assert(store.get('foo').cat == 'mat')
store.update('foo', function(foo) {
foo.cat = 'mat2'
})
assert(store.get('foo').cat == 'mat2')
})
test('update return value', function() {
store.clearAll()
store.update('foo', function(foo) {
assert(foo == undefined)
return { cat:'mat4' }
})
assert(store.get('foo').cat == 'mat4')
})
test('update default value', function() {
store.clearAll()
store.update('foo2', {}, function(foo2) {
foo2.bar = 'cat'
})
assert(store.get('foo2').bar == 'cat')
})
test('update default value + return', function() {
store.clearAll()
store.update('foo2', [], function(foor2) {
return { bar2:'cat2' }
})
assert(typeof store.get('foo2') == 'object')
assert(store.get('foo2').bar == undefined)
assert(store.get('foo2').bar2 == 'cat2')
})
}