-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (59 loc) · 1.63 KB
/
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
// cspell:word supertape
import { test } from 'supertape'
import { IceCube } from './index.js'
function getError(func, t) {
try {
func()
t.fail('No error.')
} catch(e) {
return e.message
}
}
test('initialization: validate error', (t) => {
const fail = () => new IceCube(1234)
t.equal(getError(fail, t), 'Iced can only be used with objects...')
t.end()
})
test('initialization: "iced" preset', (t) => {
const fail = () => new IceCube({ iced: true })
t.equal(
getError(fail, t),
'You cannot pre-set the iced property into Iced: this is an Iced reserved keyword.'
)
t.end()
})
test('options: iced (default)', (t) => {
const obj = new IceCube({})
t.equal(obj.iced, true)
})
test('options: iced = false', (t) => {
const obj = new IceCube({}, { iced: false })
t.equal(obj.iced, false)
})
test('object: read properties while iced', (t) => {
const obj = new IceCube({ test: true })
t.equal(obj.test, true)
t.end()
})
test('object: read properties while not iced', (t) => {
const obj = new IceCube({ test: true })
obj.iced = false
t.equal(obj.test, true)
t.end()
})
test('object: error on edit when iced', (t) => {
const obj = new IceCube({ test: true })
const fail = () => obj.test = false
t.equal(
getError(fail, t),
'This object is iced: you cannot edit any value. To edit, set the "iced" property to false.'
)
t.end()
})
test('object: success on edit when not iced', (t) => {
const obj = new IceCube({ test: true })
obj.iced = false
obj.test = false
t.equal(obj.test, false)
t.end()
})