/
snapshot.test.ts
66 lines (56 loc) · 1.46 KB
/
snapshot.test.ts
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
import { expect, test } from 'vitest'
test('snapshot', () => {
expect({
this: { is: new Set(['of', 'snapshot']) },
}).toMatchSnapshot()
})
test('inline snapshot', () => {
expect('inline string').toMatchInlineSnapshot('"inline string"')
expect({ foo: { type: 'object', map: new Map() } }).toMatchInlineSnapshot(`
{
"foo": {
"map": Map {},
"type": "object",
},
}`)
})
test('snapshot with big array', () => {
expect({
this: { is: new Set(['one', new Array(30).fill({})]) },
}).toMatchSnapshot()
})
test('snapshot with big string', () => {
expect({
this: { is: new Set(['one', new Array(30).fill('zoo').join()]) },
}).toMatchSnapshot()
})
test('throwing snapshots', () => {
expect(() => {
throw new Error('omega')
}).toThrowErrorMatchingSnapshot()
expect(() => {
// eslint-disable-next-line no-throw-literal
throw 'omega'
}).toThrowErrorMatchingSnapshot()
expect(() => {
// eslint-disable-next-line no-throw-literal
throw { error: 'omega' }
}).toThrowErrorMatchingSnapshot()
})
test('throwing inline snapshots', () => {
expect(() => {
throw new Error('omega')
}).toThrowErrorMatchingInlineSnapshot('"omega"')
expect(() => {
// eslint-disable-next-line no-throw-literal
throw 'omega'
}).toThrowErrorMatchingInlineSnapshot('"omega"')
expect(() => {
// eslint-disable-next-line no-throw-literal
throw { error: 'omega' }
}).toThrowErrorMatchingInlineSnapshot(`
{
"error": "omega",
}
`)
})