-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjects.spec.js
80 lines (64 loc) · 1.67 KB
/
objects.spec.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
import {
cloneDeep,
defineDefaults,
defineProperties,
defineProperty,
filter,
pick,
} from './objects.js'
import { expect } from 'chai'
describe('Objects', function () {
it('defineProperty', () => {
const source = {}
defineProperty(source, 'name', 'hello')
expect(source.name).to.be.equal('hello')
expect(() => {
source.name = 'goodbye'
}).to.throw()
})
it('defineProperties', () => {
const source = {}
defineProperties(source, {
name: 'hello',
})
expect(source.name).to.be.equal('hello')
expect(() => {
source.name = 'goodbye'
}).to.throw()
})
it('defineDefaults', () => {
const source = {
name: 'hello',
}
defineDefaults(source, {
name: 'goodbye',
surname: 'hello',
})
expect(source.name).to.be.equal('hello')
})
it('cloneDeep', () => {
const source = { name: 'hello' }
const clone = cloneDeep(source)
source.surname = 'goodbye'
expect(clone.surname).to.be.not.ok
expect(clone.name).to.be.equal('hello')
})
it('filter', () => {
const source = { name: 'hello', class: 'test' }
const filtered = filter(source, (key) => key === 'name')
expect(filtered.class).to.be.not.ok
expect(filtered.name).to.be.equal('hello')
})
it('filter (null)', () => {
expect(() => filter(null, (key) => key === 'name')).to.not.throw()
})
it('pick', () => {
const source = { name: 'hello', class: 'test' }
const filtered = pick(source, ['name'])
expect(filtered.class).to.be.not.ok
expect(filtered.name).to.be.equal('hello')
})
it('pick (null)', () => {
expect(() => pick(null, ['name'])).to.not.throw()
})
})