This repository was archived by the owner on Mar 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremove.js
More file actions
64 lines (49 loc) · 1.32 KB
/
Copy pathremove.js
File metadata and controls
64 lines (49 loc) · 1.32 KB
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
'use strict'
import assert from 'assert'
import operations from '../lib/operations'
describe('remove', () => {
let doc
const remove = function(path) {
return operations.remove(doc, path)
}
describe('object location', () => {
it('removes and returns the value if the location exists', () => {
doc = {foo: 'bar'}
const r = remove('/foo')
assert.strictEqual(Object.keys(r[0]).length, 0)
assert.strictEqual(r[1], 'bar')
})
it('throws an error if the location does not exists', () => {
doc = {}
assert.throws(() => {
remove('/foo')
}, Error)
})
it('throws an error if the path cannot be walked', () => {
doc = {}
assert.throws(() => {
remove('/foo/bar')
}, Error)
})
})
describe('array location', () => {
it('removes and returns the value if the location exists', () => {
doc = ['bar']
const r = remove('/0')
assert.strictEqual(r[0].length, 0)
assert.strictEqual(r[1], 'bar')
})
it('throws an error if the location does not exists', () => {
doc = []
assert.throws(() => {
remove('/0')
}, Error)
})
it('throws an error if the path cannot be walked', () => {
doc = {}
assert.throws(() => {
remove('/foo/0')
}, Error)
})
})
})