1 | import {
|
2 | AbstractView, Component, ComponentClass,
|
3 | ReactElement, ReactInstance, ClassType,
|
4 | DOMElement, FunctionComponentElement, CElement,
|
5 | ReactHTMLElement, DOMAttributes, FC
|
6 | } from 'react';
|
7 |
|
8 | import * as ReactTestUtils from ".";
|
9 |
|
10 | export {};
|
11 |
|
12 | export interface OptionalEventProperties {
|
13 | bubbles?: boolean | undefined;
|
14 | cancelable?: boolean | undefined;
|
15 | currentTarget?: EventTarget | undefined;
|
16 | defaultPrevented?: boolean | undefined;
|
17 | eventPhase?: number | undefined;
|
18 | isTrusted?: boolean | undefined;
|
19 | nativeEvent?: Event | undefined;
|
20 | preventDefault?(): void;
|
21 | stopPropagation?(): void;
|
22 | target?: EventTarget | undefined;
|
23 | timeStamp?: Date | undefined;
|
24 | type?: string | undefined;
|
25 | }
|
26 |
|
27 | export type ModifierKey = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Hyper" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Super" | "Symbol" | "SymbolLock";
|
28 |
|
29 | export interface SyntheticEventData extends OptionalEventProperties {
|
30 | altKey?: boolean | undefined;
|
31 | button?: number | undefined;
|
32 | buttons?: number | undefined;
|
33 | clientX?: number | undefined;
|
34 | clientY?: number | undefined;
|
35 | changedTouches?: TouchList | undefined;
|
36 | charCode?: number | undefined;
|
37 | clipboardData?: DataTransfer | undefined;
|
38 | ctrlKey?: boolean | undefined;
|
39 | deltaMode?: number | undefined;
|
40 | deltaX?: number | undefined;
|
41 | deltaY?: number | undefined;
|
42 | deltaZ?: number | undefined;
|
43 | detail?: number | undefined;
|
44 | getModifierState?(key: ModifierKey): boolean;
|
45 | key?: string | undefined;
|
46 | keyCode?: number | undefined;
|
47 | locale?: string | undefined;
|
48 | location?: number | undefined;
|
49 | metaKey?: boolean | undefined;
|
50 | pageX?: number | undefined;
|
51 | pageY?: number | undefined;
|
52 | relatedTarget?: EventTarget | undefined;
|
53 | repeat?: boolean | undefined;
|
54 | screenX?: number | undefined;
|
55 | screenY?: number | undefined;
|
56 | shiftKey?: boolean | undefined;
|
57 | targetTouches?: TouchList | undefined;
|
58 | touches?: TouchList | undefined;
|
59 | view?: AbstractView | undefined;
|
60 | which?: number | undefined;
|
61 | }
|
62 |
|
63 | export type EventSimulator = (element: Element | Component<any>, eventData?: SyntheticEventData) => void;
|
64 |
|
65 | export interface MockedComponentClass {
|
66 | new (props: any): any;
|
67 | }
|
68 |
|
69 | export interface ShallowRenderer {
|
70 | |
71 |
|
72 |
|
73 | getRenderOutput<E extends ReactElement>(): E;
|
74 | |
75 |
|
76 |
|
77 | render(element: ReactElement, context?: any): void;
|
78 | unmount(): void;
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export namespace Simulate {
|
86 | const abort: EventSimulator;
|
87 | const animationEnd: EventSimulator;
|
88 | const animationIteration: EventSimulator;
|
89 | const animationStart: EventSimulator;
|
90 | const blur: EventSimulator;
|
91 | const cancel: EventSimulator;
|
92 | const canPlay: EventSimulator;
|
93 | const canPlayThrough: EventSimulator;
|
94 | const change: EventSimulator;
|
95 | const click: EventSimulator;
|
96 | const close: EventSimulator;
|
97 | const compositionEnd: EventSimulator;
|
98 | const compositionStart: EventSimulator;
|
99 | const compositionUpdate: EventSimulator;
|
100 | const contextMenu: EventSimulator;
|
101 | const copy: EventSimulator;
|
102 | const cut: EventSimulator;
|
103 | const auxClick: EventSimulator;
|
104 | const doubleClick: EventSimulator;
|
105 | const drag: EventSimulator;
|
106 | const dragEnd: EventSimulator;
|
107 | const dragEnter: EventSimulator;
|
108 | const dragExit: EventSimulator;
|
109 | const dragLeave: EventSimulator;
|
110 | const dragOver: EventSimulator;
|
111 | const dragStart: EventSimulator;
|
112 | const drop: EventSimulator;
|
113 | const durationChange: EventSimulator;
|
114 | const emptied: EventSimulator;
|
115 | const encrypted: EventSimulator;
|
116 | const ended: EventSimulator;
|
117 | const error: EventSimulator;
|
118 | const focus: EventSimulator;
|
119 | const input: EventSimulator;
|
120 | const invalid: EventSimulator;
|
121 | const keyDown: EventSimulator;
|
122 | const keyPress: EventSimulator;
|
123 | const keyUp: EventSimulator;
|
124 | const load: EventSimulator;
|
125 | const loadStart: EventSimulator;
|
126 | const loadedData: EventSimulator;
|
127 | const loadedMetadata: EventSimulator;
|
128 | const mouseDown: EventSimulator;
|
129 | const mouseEnter: EventSimulator;
|
130 | const mouseLeave: EventSimulator;
|
131 | const mouseMove: EventSimulator;
|
132 | const mouseOut: EventSimulator;
|
133 | const mouseOver: EventSimulator;
|
134 | const mouseUp: EventSimulator;
|
135 | const paste: EventSimulator;
|
136 | const pause: EventSimulator;
|
137 | const play: EventSimulator;
|
138 | const playing: EventSimulator;
|
139 | const progress: EventSimulator;
|
140 | const pointerCancel: EventSimulator;
|
141 | const pointerDown: EventSimulator;
|
142 | const pointerUp: EventSimulator;
|
143 | const pointerMove: EventSimulator;
|
144 | const pointerOut: EventSimulator;
|
145 | const pointerOver: EventSimulator;
|
146 | const pointerEnter: EventSimulator;
|
147 | const pointerLeave: EventSimulator;
|
148 | const gotPointerCapture: EventSimulator;
|
149 | const lostPointerCapture: EventSimulator;
|
150 | const rateChange: EventSimulator;
|
151 | const reset: EventSimulator;
|
152 | const resize: EventSimulator;
|
153 | const scroll: EventSimulator;
|
154 | const toggle: EventSimulator;
|
155 | const seeked: EventSimulator;
|
156 | const seeking: EventSimulator;
|
157 | const select: EventSimulator;
|
158 | const beforeInput: EventSimulator;
|
159 | const stalled: EventSimulator;
|
160 | const submit: EventSimulator;
|
161 | const suspend: EventSimulator;
|
162 | const timeUpdate: EventSimulator;
|
163 | const touchCancel: EventSimulator;
|
164 | const touchEnd: EventSimulator;
|
165 | const touchMove: EventSimulator;
|
166 | const touchStart: EventSimulator;
|
167 | const transitionEnd: EventSimulator;
|
168 | const volumeChange: EventSimulator;
|
169 | const waiting: EventSimulator;
|
170 | const wheel: EventSimulator;
|
171 | }
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | export function renderIntoDocument<T extends Element>(
|
177 | element: DOMElement<any, T>): T;
|
178 | export function renderIntoDocument(
|
179 | element: FunctionComponentElement<any>): void;
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | export function renderIntoDocument<P, T extends Component<P>>(
|
185 | element: CElement<P, T>): T;
|
186 | export function renderIntoDocument<P>(
|
187 | element: ReactElement<P>): Component<P> | Element | void;
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | export function mockComponent(
|
195 | mocked: MockedComponentClass, mockTagName?: string): typeof ReactTestUtils;
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export function isElement(element: any): boolean;
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | export function isElementOfType<T extends HTMLElement>(
|
206 | element: ReactElement, type: string): element is ReactHTMLElement<T>;
|
207 |
|
208 |
|
209 |
|
210 | export function isElementOfType<P extends DOMAttributes<{}>, T extends Element>(
|
211 | element: ReactElement, type: string): element is DOMElement<P, T>;
|
212 |
|
213 |
|
214 |
|
215 | export function isElementOfType<P>(
|
216 | element: ReactElement, type: FC<P>): element is FunctionComponentElement<P>;
|
217 |
|
218 |
|
219 |
|
220 | export function isElementOfType<P, T extends Component<P>, C extends ComponentClass<P>>(
|
221 | element: ReactElement, type: ClassType<P, T, C>): element is CElement<P, T>;
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | export function isDOMComponent(instance: ReactInstance): instance is Element;
|
227 |
|
228 |
|
229 |
|
230 | export function isCompositeComponent(instance: ReactInstance): instance is Component<any>;
|
231 |
|
232 |
|
233 |
|
234 | export function isCompositeComponentWithType<T extends Component<any>, C extends ComponentClass<any>>(
|
235 | instance: ReactInstance, type: ClassType<any, T, C>): boolean;
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 | export function findAllInRenderedTree(
|
243 | root: Component<any>,
|
244 | fn: (i: ReactInstance) => boolean): ReactInstance[];
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | export function scryRenderedDOMComponentsWithClass(
|
251 | root: Component<any>,
|
252 | className: string): Element[];
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | export function findRenderedDOMComponentWithClass(
|
259 | root: Component<any>,
|
260 | className: string): Element;
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | export function scryRenderedDOMComponentsWithTag(
|
267 | root: Component<any>,
|
268 | tagName: string): Element[];
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | export function findRenderedDOMComponentWithTag(
|
275 | root: Component<any>,
|
276 | tagName: string): Element;
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | export function scryRenderedComponentsWithType<T extends Component<any>, C extends ComponentClass<any>>(
|
282 | root: Component<any>,
|
283 | type: ClassType<any, T, C>): T[];
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 | export function findRenderedComponentWithType<T extends Component<any>, C extends ComponentClass<any>>(
|
291 | root: Component<any>,
|
292 | type: ClassType<any, T, C>): T;
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | export function createRenderer(): ShallowRenderer;
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | declare const UNDEFINED_VOID_ONLY: unique symbol;
|
316 |
|
317 | type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
|
318 |
|
319 | export function act(callback: () => VoidOrUndefinedOnly): void;
|
320 | export function act<T>(callback: () => T | Promise<T>): Promise<T>;
|
321 |
|
322 |
|
323 |
|
324 | export interface DebugPromiseLike {
|
325 |
|
326 | then(onfulfilled: (value: never) => never, onrejected: (reason: never) => never): never;
|
327 | }
|