/
suspense.spec.ts
67 lines (54 loc) · 1.73 KB
/
suspense.spec.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
67
import { beforeEach, describe, expect, test, vi } from 'vitest'
import SuspenseComponent from '../components/Suspense.vue'
import { mount, flushPromises } from '../../src'
import { defineComponent } from 'vue'
let mockShouldError = false
vi.mock('../utils', () => ({
simulateDelay: () => {
if (mockShouldError) {
throw new Error('Error!')
}
}
}))
beforeEach(() => {
mockShouldError = false
})
describe('suspense', () => {
test('fallback state', () => {
const wrapper = mount(SuspenseComponent)
expect(wrapper.html()).toContain('Fallback content')
})
test('default state', async () => {
const wrapper = mount(SuspenseComponent)
await flushPromises()
expect(wrapper.html()).toContain('Default content')
})
test('error state', async () => {
mockShouldError = true
const wrapper = mount(SuspenseComponent)
await flushPromises()
expect(wrapper.html()).toContain('Error!')
})
test('returns the element if it is a multi root element inside Suspense', () => {
const Async = defineComponent({
template: '<h1>Hello</h1><span id="my-span">There</span>'
})
const Component = defineComponent({
components: { Async },
template: '<Suspense><Async/></Suspense>'
})
const wrapper = mount(Component)
expect(wrapper.get('#my-span')).not.toBeNull()
})
test('returns the element if it is a root element inside Suspense', () => {
const Async = defineComponent({
template: '<div><h1>Hello</h1><span id="my-span">There</span></div>'
})
const Component = defineComponent({
components: { Async },
template: '<Suspense><Async/></Suspense>'
})
const wrapper = mount(Component)
expect(wrapper.get('#my-span')).not.toBeNull()
})
})