-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathtest.ts
124 lines (108 loc) · 2.61 KB
/
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
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
119
120
121
122
123
124
import Vue from 'vue'
import {render, fireEvent, screen, waitFor} from '@testing-library/vue'
declare const elem: HTMLElement
const SomeComponent = Vue.extend({
name: 'SomeComponent',
props: {
foo: Number,
bar: String,
},
})
async function testRender() {
const page = render({template: '<div />'})
// single queries
page.getByText('foo')
page.queryByText('foo')
await page.findByText('foo')
// multiple queries
page.getAllByText('bar')
page.queryAllByText('bar')
await page.findAllByText('bar')
// helpers
const {container, unmount, debug} = page
debug(elem) // $ExpectType void
debug([elem, elem], 100, {highlight: false}) // $ExpectType void
}
async function testRenderOptions() {
const container = document.createElement('div')
const options = {container}
render({template: 'div'}, options)
}
async function testFireEvent() {
const {container} = render({template: 'button'})
await fireEvent.click(container)
}
async function testDebug() {
const {debug, getAllByTestId} = render({
render(h) {
return h('div', [
h('h1', {attrs: {'data-testId': 'testid'}}, 'hello world'),
h('h2', {attrs: {'data-testId': 'testid'}}, 'hello world'),
])
},
})
debug(getAllByTestId('testid'))
}
async function testScreen() {
render({template: 'button'})
await screen.findByRole('button')
}
async function testWaitFor() {
const {container} = render({template: 'button'})
fireEvent.click(container)
await waitFor(() => {})
}
async function testOptions() {
render(SomeComponent, {
// options for new Vue()
name: 'SomeComponent',
methods: {
glorb() {
return 42
},
},
// options for vue-test-utils mount()
slots: {
quux: '<p>Baz</p>',
},
mocks: {
isThisFake() {
return true
},
},
// options for Vue Testing Library render()
container: elem,
baseElement: elem,
props: {
foo: 9,
bar: 'x',
},
store: {
state: {
foos: [4, 5],
bars: ['a', 'b'],
},
getters: {
fooCount() {
return this.foos.length
},
},
},
routes: [
{path: '/', name: 'home', component: SomeComponent},
{
path: '/about',
name: 'about',
component: () => Promise.resolve(SomeComponent),
},
],
})
}
function testConfigCallback() {
const ExamplePlugin: Vue.PluginFunction<never> = () => {}
render(SomeComponent, {}, (localVue, store, router) => {
localVue.use(ExamplePlugin)
store.replaceState({foo: 'bar'})
router.onError(error => console.log(error.message))
})
}