-
Notifications
You must be signed in to change notification settings - Fork 18
/
spec.js
118 lines (104 loc) · 2.34 KB
/
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const snapshot = require('.')
const { stripIndent } = require('common-tags')
const la = require('lazy-ass')
const R = require('ramda')
const add = (a, b) => a + b
/* eslint-env mocha */
describe('find object by property', () => {
it('using Ramda', () => {
const list = [
{
a: 1,
b: 1
},
{
a: 2,
b: 2
}
]
const item = {
b: 2
}
const found = R.find(R.propEq('b', item.b), list)
la(found === list[1], 'found wrong item', found)
})
})
describe('spec file', () => {
it('returns saved value and snapshot key', () => {
const result = snapshot('my name', 42)
la(result.value === 42, 'wrong value', result)
la(result.key === 'my name', 'wrong key', result)
})
it('uses spec name', () => {
let result = snapshot(42)
la(result.value === 42, 'wrong value', result)
// first snapshot in this test has index 1
la(result.key === 'spec file uses spec name 1', 'wrong key', result)
// second snapshot
result = snapshot('foo')
la(result.value === 'foo', 'wrong value', result)
// second snapshot in this test has index 2
la(result.key === 'spec file uses spec name 2', 'wrong key', result)
})
it('adds 2 numbers', () => {
snapshot(add(2, 3))
})
it('without snapshot', () => {
console.assert(add(2, 10) === 12)
})
it('has several snapshot numbers', () => {
snapshot(1)
snapshot(2)
snapshot(3)
snapshot(4)
snapshot(5)
})
it('supports promises', () => {
return Promise.resolve(42).then(snapshot)
})
describe('inner tests', () => {
it('works in nested describes', () => {
snapshot('foo')
})
})
})
describe('example', () => {
it('works', () => {
snapshot(add(10, 20))
snapshot('a text message')
return Promise.resolve(42).then(snapshot)
})
})
describe('multi line text', () => {
it('works', () => {
snapshot(`
line 1
line 2
line 3
`)
})
it('works with longer text', () => {
const text = stripIndent`
first line
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
`
snapshot(text)
})
})
describe('multi line text with backticks', () => {
it('works and saves', () => {
snapshot(`
line 1
line 2 with \`42\`
line 3 with \`foo\`
`)
})
})