forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing-library__vue-tests.ts
145 lines (132 loc) · 8.33 KB
/
testing-library__vue-tests.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import * as lib from '@testing-library/vue';
import Vue from 'vue';
declare const elem: HTMLElement;
declare const input: HTMLInputElement;
declare const select: HTMLSelectElement;
declare const option: HTMLOptionElement;
declare const textarea: HTMLTextAreaElement;
const SomeComponent = Vue.extend({
name: 'SomeComponent',
props: {
foo: Number,
bar: String,
},
});
lib.render(Vue);
lib.render(SomeComponent);
const component = lib.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()
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)},
],
});
component.container; // $ExpectType HTMLElement
component.baseElement; // $ExpectType HTMLBodyElement
component.debug(); // $ExpectType void
component.debug(elem); // $ExpectType void
component.unmount(); // $ExpectType void
component.isUnmounted(); // $ExpectType boolean
component.html(); // $ExpectType string
component.emitted(); // $ExpectType { [name: string]: any[][]; }
component.updateProps({foo: "bar"}); // $ExpectType Promise<void>
// Has bound queries
component.getByLabelText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement
component.getByPlaceholderText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByAltText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByTitle(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByDisplayValue(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByRole(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByTestId(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
component.getByText("foo"); // $ExpectType HTMLElement
component.getByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement
component.getAllByText("foo"); // $ExpectType HTMLElement[]
component.getAllByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement[]
component.queryByText("foo"); // $ExpectType HTMLElement | null
component.queryByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement | null
component.queryAllByText("foo"); // $ExpectType HTMLElement[]
component.queryAllByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement[]
component.findByText("foo"); // $ExpectType Promise<HTMLElement>
component.findByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType Promise<HTMLElement>
component.findAllByText("foo"); // $ExpectType Promise<HTMLElement[]>
component.findAllByText(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType Promise<HTMLElement[]>
lib.cleanup(); // $ExpectType void
// Reexports queries from dom-testing-library
lib.getByLabelText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement
lib.getByPlaceholderText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByAltText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByTitle(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByDisplayValue(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByRole(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByTestId(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
lib.getByText(elem, "foo"); // $ExpectType HTMLElement
lib.getByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement
lib.getAllByText(elem, "foo"); // $ExpectType HTMLElement[]
lib.getAllByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement[]
lib.queryByText(elem, "foo"); // $ExpectType HTMLElement | null
lib.queryByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement | null
lib.queryAllByText(elem, "foo"); // $ExpectType HTMLElement[]
lib.queryAllByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType HTMLElement[]
lib.findByText(elem, "foo"); // $ExpectType Promise<HTMLElement>
lib.findByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType Promise<HTMLElement>
lib.findAllByText(elem, "foo"); // $ExpectType Promise<HTMLElement[]>
lib.findAllByText(elem, /some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x, selector: '*'}); // $ExpectType Promise<HTMLElement[]>
// Reexports createEvent from dom-testing-library
lib.createEvent.click(elem); // $ExpectType Event
lib.createEvent.click(elem, {foo: "bar"}); // $ExpectType Event
lib.createEvent.keyDown(elem); // $ExpectType Event
lib.createEvent.mouseEnter(elem); // $ExpectType Event
// Changes fireEvent to be asynchronous
lib.fireEvent(elem, new Event('change')); // $ExpectType Promise<void>
lib.fireEvent.click(elem); // $ExpectType Promise<void>
lib.fireEvent.click(elem, {foo: "bar"}); // $ExpectType Promise<void>
lib.fireEvent.keyDown(elem); // $ExpectType Promise<void>
lib.fireEvent.mouseEnter(elem); // $ExpectType Promise<void>
// Adds update() function
lib.fireEvent.update(input, "foo"); // $ExpectType Promise<void>
lib.fireEvent.update(select, "bar"); // $ExpectType Promise<void>
lib.fireEvent.update(textarea, "some\ntext"); // $ExpectType Promise<void>
lib.fireEvent.update(option); // $ExpectType Promise<void>
// Adds touch() function
lib.fireEvent.touch(elem); // $ExpectType Promise<void>
// Reexports async functions from dom-testing-library
lib.wait(); // $ExpectType Promise<void>
lib.wait(() => { throw new Error("nope"); }, {timeout: 3000, interval: 100});
lib.waitForDomChange({container: select, timeout: 3000, mutationObserverOptions: {subtree: false}});
lib.waitForElement(() => input); // $ExpectType Promise<HTMLInputElement>
lib.waitForElement(() => option, {container: select, timeout: 3000, mutationObserverOptions: {subtree: false}}); // $ExpectType Promise<HTMLOptionElement>
lib.waitForElementToBeRemoved(() => input); // $ExpectType Promise<void>
lib.waitForElementToBeRemoved(() => option, {container: select, timeout: 3000, mutationObserverOptions: {subtree: false}}); // $ExpectType Promise<void>
// Reexports utilities from dom-testing-library
lib.buildQueries((el: HTMLElement) => [el], (_: HTMLElement) => "something", (_: HTMLElement) => "error");
lib.within(elem);
lib.getQueriesForElement(elem);
lib.getNodeText(elem); // $ExpectType string
lib.getRoles(elem); // $ExpectType { [index: string]: HTMLElement[]; }
lib.prettyDOM(elem); // $ExpectType string | false
lib.logRoles(elem); // $ExpectType string