-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.js
88 lines (71 loc) · 2.02 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const { createFormatter } = require('./')
const test = require('ava')
const format = createFormatter()
test('merges with default formatter', (t) => {
const customFormat = createFormatter({
formatter: { number: (n) => -1 }
})
const out = customFormat({ str: 'str', val: 10 })
t.true(out.includes('-1'))
t.false(out.includes('10'))
t.true(out.includes('str'))
})
test('literals', (t) => {
t.true(format({ val: true }).includes('true'))
t.true(format({ val: false }).includes('false'))
t.true(format({ val: null }).includes('null'))
t.true(format({ val: undefined }).includes('undefined'))
})
test('strings', (t) => {
t.true(format({ val: 'hello world' }).includes('"hello world"'))
})
test('numbers', (t) => {
t.true(format({ val: 12 }).includes('12'))
t.true(format({ val: 12e10 }).includes('120000000000'))
t.true(format({ val: 9.99 }).includes('9.99'))
t.true(format({ val: -200 }).includes('-200'))
t.true(format({ val: Infinity }).includes('Infinity'))
})
test('functions', (t) => {
const normalFn = format({ helloWorld: () => {} })
t.true(normalFn.includes('[Function helloWorld]'))
const genFn = format({ helloWorld: function *() {} })
t.true(genFn.includes('[GeneratorFunction helloWorld]'))
})
test('depth', (t) => {
const actual = {
a: {
b: true,
c: {
d: true
}
}
}
const fmtNoDepth = format(actual, 0)
t.true(fmtNoDepth.includes('(collapsed)'))
t.false(fmtNoDepth.includes('b: true'))
t.false(fmtNoDepth.includes('d: true'))
const fmtOneLevel = format(actual, 1)
t.true(fmtOneLevel.includes('(collapsed)'))
t.true(fmtOneLevel.includes('b: true'))
t.false(fmtOneLevel.includes('d: true'))
})
test('references', (t) => {
const c = { prop: true }
const actual = {
a: c,
b: c
}
const fmt = format(actual)
t.true(fmt.includes('References ~a'))
})
test('circular', (t) => {
let actual = {
body: {
a: true
}
}
actual.body.b = actual.body
const fmt = format(actual)
t.true(fmt.includes('References ~body'))
})