-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathindex.test-d.ts
100 lines (82 loc) · 2.65 KB
/
index.test-d.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
import {expectType} from 'tsd'
import {defineComponent} from 'vue'
import {render, fireEvent, screen, waitFor} from '.'
declare const elem: Element
const SomeComponent = defineComponent({
name: 'SomeComponent',
props: {
foo: {type: Number, default: 0},
bar: {type: String, default: '0'},
},
})
export async function testRender() {
const utils = render({template: '<div />'})
// single queries
expectType<HTMLElement>(utils.getByText('foo'))
expectType<HTMLElement | null>(utils.queryByText('foo'))
expectType<HTMLElement>(await utils.findByText('foo'))
// multiple queries
expectType<HTMLElement[]>(utils.getAllByText('bar'))
expectType<HTMLElement[]>(utils.queryAllByText('bar'))
expectType<HTMLElement[]>(await utils.findAllByText('bar'))
// helpers
const {container, baseElement, unmount, debug, rerender} = utils
expectType<void>(await rerender({a: 1}))
expectType<void>(debug())
expectType<void>(debug(container))
expectType<void>(debug([elem, elem], 100, {highlight: false}))
expectType<void>(unmount())
expectType<Element>(container)
expectType<Element>(baseElement)
}
export function testRenderOptions() {
const container = document.createElement('div')
const baseElement = document.createElement('div')
const options = {container, baseElement}
render({template: 'div'}, options)
}
export async function testFireEvent() {
const {container} = render({template: 'button'})
expectType<void>(await fireEvent.click(container))
expectType<void>(await fireEvent.touch(elem))
}
export async function testScreen() {
render({template: 'button'})
expectType<HTMLElement>(await screen.findByRole('button'))
}
export async function testWaitFor() {
const {container} = render({template: 'button'})
expectType<void>(await fireEvent.update(container))
expectType<void>(await waitFor(() => {}))
}
export function testOptions() {
render(SomeComponent, {
attrs: {a: 1},
props: {foo: 1},
data: () => ({b: 2}),
slots: {
default: '<div />',
footer: '<div />',
},
global: {
config: {isCustomElement: _ => true},
plugins: [],
},
baseElement: document.createElement('div'),
container: document.createElement('div'),
})
}
export function testEmitted() {
const {emitted} = render(SomeComponent)
expectType<unknown[]>(emitted().foo)
expectType<unknown[]>(emitted('foo'))
}
/*
eslint
testing-library/prefer-explicit-assert: "off",
testing-library/no-wait-for-empty-callback: "off",
testing-library/no-debugging-utils: "off",
testing-library/prefer-screen-queries: "off",
@typescript-eslint/unbound-method: "off",
@typescript-eslint/no-invalid-void-type: "off"
*/