-
Notifications
You must be signed in to change notification settings - Fork 22
/
testUtils.ts
48 lines (42 loc) · 1.05 KB
/
testUtils.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
import type { DOMWrapper, VueWrapper } from '@vue/test-utils'
type WrappedElement = Omit<DOMWrapper<Element>, 'exists'>
export function getByClass(
wrapper: VueWrapper<any>,
className: string,
): WrappedElement {
return wrapper.get(`.${className}`)
}
export function getById(
wrapper: VueWrapper<any>,
testId: string,
): WrappedElement {
return wrapper.get(`#${testId}`)
}
export function getByQuery(
wrapper: VueWrapper<any>,
query: string,
): WrappedElement {
return wrapper.get(query)
}
export function getByTestId(
wrapper: VueWrapper<any>,
testId: string,
): WrappedElement {
return wrapper.get(`[data-testid="${testId}"]`)
}
export function getHTMLElement(wrappedElement: WrappedElement): HTMLElement {
return wrappedElement.getRootNodes()[0] as HTMLElement
}
export async function typeString(
wrappedElement: WrappedElement,
toType: string,
): Promise<void> {
Promise.all([
wrappedElement.trigger('click'),
...toType.split('').map((c) =>
wrappedElement.trigger('keyup', {
key: c,
}),
),
])
}