UNPKG

29.6 kBTypeScriptView Raw
1// Type definitions for Enzyme 3.10
2// Project: https://github.com/airbnb/enzyme
3// Definitions by: Marian Palkus <https://github.com/MarianPalkus>
4// Cap3 <http://www.cap3.de>
5// Ivo Stratev <https://github.com/NoHomey>
6// jwbay <https://github.com/jwbay>
7// huhuanming <https://github.com/huhuanming>
8// MartynasZilinskas <https://github.com/MartynasZilinskas>
9// Torgeir Hovden <https://github.com/thovden>
10// Martin Hochel <https://github.com/hotell>
11// Christian Rackerseder <https://github.com/screendriver>
12// Mateusz Sokoła <https://github.com/mateuszsokola>
13// Braiden Cutforth <https://github.com/braidencutforth>
14// Erick Zhao <https://github.com/erickzhao>
15// Jack Tomaszewski <https://github.com/jtomaszewski>
16// Jordan Harband <https://github.com/ljharb>
17// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
18// TypeScript Version: 3.1
19
20/// <reference types="cheerio" />
21import {
22 ReactElement,
23 Component,
24 AllHTMLAttributes as ReactHTMLAttributes,
25 SVGAttributes as ReactSVGAttributes,
26} from 'react';
27
28export type HTMLAttributes = ReactHTMLAttributes<{}> & ReactSVGAttributes<{}>;
29
30export class ElementClass extends Component<any, any> {}
31
32/* These are purposefully stripped down versions of React.ComponentClass and React.StatelessComponent.
33 * The optional static properties on them break overload ordering for wrapper methods if they're not
34 * all specified in the implementation. TS chooses the EnzymePropSelector overload and loses the generics
35 */
36export interface ComponentClass<Props> {
37 new (props: Props, context?: any): Component<Props>;
38}
39
40export type StatelessComponent<Props> = (props: Props, context?: any) => JSX.Element | null;
41
42export type ComponentType<Props> = ComponentClass<Props> | StatelessComponent<Props>;
43
44/**
45 * Many methods in Enzyme's API accept a selector as an argument. Selectors in Enzyme can fall into one of the
46 * following three categories:
47 *
48 * 1. A Valid CSS Selector
49 * 2. A React Component Constructor
50 * 3. A React Component's displayName
51 * 4. A React Stateless component
52 * 5. A React component property map
53 */
54export interface EnzymePropSelector {
55 [key: string]: any;
56}
57export type EnzymeSelector = string | StatelessComponent<any> | ComponentClass<any> | EnzymePropSelector;
58
59export type Intercepter<T> = (intercepter: T) => void;
60
61export interface CommonWrapper<P = {}, S = {}, C = Component<P, S>> {
62 /**
63 * Returns a new wrapper with only the nodes of the current wrapper that, when passed into the provided predicate function, return true.
64 */
65 filterWhere(predicate: (wrapper: this) => boolean): this;
66
67 /**
68 * Returns whether or not the current wrapper has a node anywhere in it's render tree that looks like the one passed in.
69 */
70 contains(node: ReactElement | ReactElement[] | string | number): boolean;
71
72 /**
73 * Returns whether or not a given react element exists in the shallow render tree.
74 */
75 containsMatchingElement(node: ReactElement | ReactElement[]): boolean;
76
77 /**
78 * Returns whether or not all the given react elements exists in the shallow render tree
79 */
80 containsAllMatchingElements(nodes: ReactElement[] | ReactElement[][]): boolean;
81
82 /**
83 * Returns whether or not one of the given react elements exists in the shallow render tree.
84 */
85 containsAnyMatchingElements(nodes: ReactElement[] | ReactElement[][]): boolean;
86
87 /**
88 * Returns whether or not the current render tree is equal to the given node, based on the expected value.
89 */
90 equals(node: ReactElement): boolean;
91
92 /**
93 * Returns whether or not a given react element matches the shallow render tree.
94 */
95 matchesElement(node: ReactElement): boolean;
96
97 /**
98 * Returns whether or not the current node has a className prop including the passed in class name.
99 */
100 hasClass(className: string | RegExp): boolean;
101
102 /**
103 * Invokes a function prop.
104 * @param invokePropName The function prop to call.
105 * @param ...args The argments to the invokePropName function
106 * @returns The value of the function.
107 */
108 invoke<
109 K extends NonNullable<
110 {
111 [K in keyof P]: P[K] extends ((...arg: any[]) => void) | undefined ? K : never;
112 }[keyof P]
113 >
114 >(
115 invokePropName: K,
116 ): P[K];
117
118 /**
119 * Returns whether or not the current node matches a provided selector.
120 */
121 is(selector: EnzymeSelector): boolean;
122
123 /**
124 * Returns whether or not the current node is empty.
125 * @deprecated Use .exists() instead.
126 */
127 isEmpty(): boolean;
128
129 /**
130 * Returns whether or not the current node exists.
131 */
132 exists(selector?: EnzymeSelector): boolean;
133
134 /**
135 * Returns a new wrapper with only the nodes of the current wrapper that don't match the provided selector.
136 * This method is effectively the negation or inverse of filter.
137 */
138 not(selector: EnzymeSelector): this;
139
140 /**
141 * Returns a string of the rendered text of the current render tree. This function should be looked at with
142 * skepticism if being used to test what the actual HTML output of the component will be. If that is what you
143 * would like to test, use enzyme's render function instead.
144 *
145 * Note: can only be called on a wrapper of a single node.
146 */
147 text(): string;
148
149 /**
150 * Returns a string of the rendered HTML markup of the current render tree.
151 *
152 * Note: can only be called on a wrapper of a single node.
153 */
154 html(): string;
155
156 /**
157 * Returns the node at a given index of the current wrapper.
158 */
159 get(index: number): ReactElement;
160
161 /**
162 * Returns the wrapper's underlying node.
163 */
164 getNode(): ReactElement;
165
166 /**
167 * Returns the wrapper's underlying nodes.
168 */
169 getNodes(): ReactElement[];
170
171 /**
172 * Returns the wrapper's underlying node.
173 */
174 getElement(): ReactElement;
175
176 /**
177 * Returns the wrapper's underlying node.
178 */
179 getElements(): ReactElement[];
180
181 /**
182 * Returns the outer most DOMComponent of the current wrapper.
183 */
184 getDOMNode<T extends Element = Element>(): T;
185
186 /**
187 * Returns a wrapper around the node at a given index of the current wrapper.
188 */
189 at(index: number): this;
190
191 /**
192 * Reduce the set of matched nodes to the first in the set.
193 */
194 first(): this;
195
196 /**
197 * Reduce the set of matched nodes to the last in the set.
198 */
199 last(): this;
200
201 /**
202 * Returns a new wrapper with a subset of the nodes of the original wrapper, according to the rules of `Array#slice`.
203 */
204 slice(begin?: number, end?: number): this;
205
206 /**
207 * Taps into the wrapper method chain. Helpful for debugging.
208 */
209 tap(intercepter: Intercepter<this>): this;
210
211 /**
212 * Returns the state hash for the root node of the wrapper. Optionally pass in a prop name and it will return just that value.
213 */
214 state(): S;
215 state<K extends keyof S>(key: K): S[K];
216 state<T>(key: string): T;
217
218 /**
219 * Returns the context hash for the root node of the wrapper. Optionally pass in a prop name and it will return just that value.
220 */
221 context(): any;
222 context<T>(key: string): T;
223
224 /**
225 * Returns the props hash for the current node of the wrapper.
226 *
227 * NOTE: can only be called on a wrapper of a single node.
228 */
229 props(): P;
230
231 /**
232 * Returns the prop value for the node of the current wrapper with the provided key.
233 *
234 * NOTE: can only be called on a wrapper of a single node.
235 */
236 prop<K extends keyof P>(key: K): P[K];
237 prop<T>(key: string): T;
238
239 /**
240 * Returns the key value for the node of the current wrapper.
241 * NOTE: can only be called on a wrapper of a single node.
242 */
243 key(): string;
244
245 /**
246 * Simulate events.
247 * Returns itself.
248 * @param args?
249 */
250 simulate(event: string, ...args: any[]): this;
251
252 /**
253 * Used to simulate throwing a rendering error. Pass an error to throw.
254 * Returns itself.
255 * @param error
256 */
257 simulateError(error: any): this;
258
259 /**
260 * A method to invoke setState() on the root component instance similar to how you might in the definition of
261 * the component, and re-renders. This method is useful for testing your component in hard to achieve states,
262 * however should be used sparingly. If possible, you should utilize your component's external API in order to
263 * get it into whatever state you want to test, in order to be as accurate of a test as possible. This is not
264 * always practical, however.
265 * Returns itself.
266 *
267 * NOTE: can only be called on a wrapper instance that is also the root instance.
268 */
269 setState<K extends keyof S>(state: Pick<S, K>, callback?: () => void): this;
270
271 /**
272 * A method that sets the props of the root component, and re-renders. Useful for when you are wanting to test
273 * how the component behaves over time with changing props. Calling this, for instance, will call the
274 * componentWillReceiveProps lifecycle method.
275 *
276 * Similar to setState, this method accepts a props object and will merge it in with the already existing props.
277 * Returns itself.
278 *
279 * NOTE: can only be called on a wrapper instance that is also the root instance.
280 */
281 setProps<K extends keyof P>(props: Pick<P, K>, callback?: () => void): this;
282
283 /**
284 * A method that sets the context of the root component, and re-renders. Useful for when you are wanting to
285 * test how the component behaves over time with changing contexts.
286 * Returns itself.
287 *
288 * NOTE: can only be called on a wrapper instance that is also the root instance.
289 */
290 setContext(context: any): this;
291
292 /**
293 * Gets the instance of the component being rendered as the root node passed into shallow().
294 *
295 * NOTE: can only be called on a wrapper instance that is also the root instance.
296 */
297 instance(): C;
298
299 /**
300 * Forces a re-render. Useful to run before checking the render output if something external may be updating
301 * the state of the component somewhere.
302 * Returns itself.
303 *
304 * NOTE: can only be called on a wrapper instance that is also the root instance.
305 */
306 update(): this;
307
308 /**
309 * Returns an html-like string of the wrapper for debugging purposes. Useful to print out to the console when
310 * tests are not passing when you expect them to.
311 */
312 debug(options?: {
313 /** Whether props should be omitted in the resulting string. Props are included by default. */
314 ignoreProps?: boolean | undefined;
315 /** Whether arrays and objects passed as props should be verbosely printed. */
316 verbose?: boolean | undefined;
317 }): string;
318
319 /**
320 * Returns the name of the current node of the wrapper.
321 */
322 name(): string;
323
324 /**
325 * Iterates through each node of the current wrapper and executes the provided function with a wrapper around
326 * the corresponding node passed in as the first argument.
327 *
328 * Returns itself.
329 * @param fn A callback to be run for every node in the collection. Should expect a ShallowWrapper as the first
330 * argument, and will be run with a context of the original instance.
331 */
332 forEach(fn: (wrapper: this, index: number) => any): this;
333
334 /**
335 * Maps the current array of nodes to another array. Each node is passed in as a ShallowWrapper to the map
336 * function.
337 * Returns an array of the returned values from the mapping function..
338 * @param fn A mapping function to be run for every node in the collection, the results of which will be mapped
339 * to the returned array. Should expect a ShallowWrapper as the first argument, and will be run
340 * with a context of the original instance.
341 */
342 map<V>(fn: (wrapper: this, index: number) => V): V[];
343
344 /**
345 * Applies the provided reducing function to every node in the wrapper to reduce to a single value. Each node
346 * is passed in as a ShallowWrapper, and is processed from left to right.
347 */
348 reduce<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R;
349
350 /**
351 * Applies the provided reducing function to every node in the wrapper to reduce to a single value.
352 * Each node is passed in as a ShallowWrapper, and is processed from right to left.
353 */
354 reduceRight<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R;
355
356 /**
357 * Returns whether or not any of the nodes in the wrapper match the provided selector.
358 */
359 some(selector: EnzymeSelector): boolean;
360
361 /**
362 * Returns whether or not any of the nodes in the wrapper pass the provided predicate function.
363 */
364 someWhere(fn: (wrapper: this) => boolean): boolean;
365
366 /**
367 * Returns whether or not all of the nodes in the wrapper match the provided selector.
368 */
369 every(selector: EnzymeSelector): boolean;
370
371 /**
372 * Returns whether or not all of the nodes in the wrapper pass the provided predicate function.
373 */
374 everyWhere(fn: (wrapper: this) => boolean): boolean;
375
376 /**
377 * Returns true if renderer returned null
378 */
379 isEmptyRender(): boolean;
380
381 /**
382 * Renders the component to static markup and returns a Cheerio wrapper around the result.
383 */
384 render(): cheerio.Cheerio;
385
386 /**
387 * Returns the type of the current node of this wrapper. If it's a composite component, this will be the
388 * component constructor. If it's native DOM node, it will be a string of the tag name.
389 *
390 * Note: can only be called on a wrapper of a single node.
391 */
392 type(): string | ComponentClass<P> | StatelessComponent<P>;
393
394 length: number;
395}
396
397export type Parameters<T> = T extends (...args: infer A) => any ? A : never;
398
399export interface ShallowWrapper<P = {}, S = {}, C = Component> extends CommonWrapper<P, S, C> {}
400export class ShallowWrapper<P = {}, S = {}, C = Component> {
401 constructor(nodes: JSX.Element[] | JSX.Element, root?: ShallowWrapper<any, any>, options?: ShallowRendererProps);
402 shallow(options?: ShallowRendererProps): ShallowWrapper<P, S>;
403 unmount(): this;
404
405 /**
406 * Find every node in the render tree that matches the provided selector.
407 * @param selector The selector to match.
408 */
409 find<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
410 find<P2>(component: ComponentType<P2>): ShallowWrapper<P2, any>;
411 find<C2 extends Component>(
412 componentClass: ComponentClass<C2['props']>,
413 ): ShallowWrapper<C2['props'], C2['state'], C2>;
414 find(props: EnzymePropSelector): ShallowWrapper<any, any>;
415 find(selector: string): ShallowWrapper<HTMLAttributes, any>;
416
417 /**
418 * Removes nodes in the current wrapper that do not match the provided selector.
419 * @param selector The selector to match.
420 */
421 filter<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
422 filter<P2>(component: ComponentType<P2>): ShallowWrapper<P2, any>;
423 filter(props: EnzymePropSelector | string): ShallowWrapper<P, S>;
424
425 /**
426 * Finds every node in the render tree that returns true for the provided predicate function.
427 */
428 findWhere(predicate: (wrapper: ShallowWrapper<any, any>) => boolean): ShallowWrapper<any, any>;
429
430 /**
431 * Returns a new wrapper with all of the children of the node(s) in the current wrapper. Optionally, a selector
432 * can be provided and it will filter the children by this selector.
433 */
434 children<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
435 children<P2>(component: ComponentType<P2>): ShallowWrapper<P2, any>;
436 children(selector: string): ShallowWrapper<HTMLAttributes, any>;
437 children(props?: EnzymePropSelector): ShallowWrapper<any, any>;
438
439 /**
440 * Returns a new wrapper with child at the specified index.
441 */
442 childAt(index: number): ShallowWrapper<any, any>;
443 childAt<P2, S2>(index: number): ShallowWrapper<P2, S2>;
444
445 /**
446 * Shallow render the one non-DOM child of the current wrapper, and return a wrapper around the result.
447 * NOTE: can only be called on wrapper of a single non-DOM component element node.
448 */
449 dive<C2 extends Component, P2 = C2['props'], S2 = C2['state']>(
450 options?: ShallowRendererProps,
451 ): ShallowWrapper<P2, S2, C2>;
452 dive<P2, S2>(options?: ShallowRendererProps): ShallowWrapper<P2, S2>;
453 dive<P2, S2, C2>(options?: ShallowRendererProps): ShallowWrapper<P2, S2, C2>;
454
455 /**
456 * Strips out all the not host-nodes from the list of nodes
457 *
458 * This method is useful if you want to check for the presence of host nodes
459 * (actually rendered HTML elements) ignoring the React nodes.
460 */
461 hostNodes(): ShallowWrapper<HTMLAttributes>;
462
463 /**
464 * Returns a wrapper around all of the parents/ancestors of the wrapper. Does not include the node in the
465 * current wrapper. Optionally, a selector can be provided and it will filter the parents by this selector.
466 *
467 * Note: can only be called on a wrapper of a single node.
468 */
469 parents<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
470 parents<P2>(component: ComponentType<P2>): ShallowWrapper<P2, any>;
471 parents(selector: string): ShallowWrapper<HTMLAttributes, any>;
472 parents(props?: EnzymePropSelector): ShallowWrapper<any, any>;
473
474 /**
475 * Returns a wrapper of the first element that matches the selector by traversing up through the current node's
476 * ancestors in the tree, starting with itself.
477 *
478 * Note: can only be called on a wrapper of a single node.
479 */
480 closest<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
481 closest<P2>(component: ComponentType<P2>): ShallowWrapper<P2, any>;
482 closest(props: EnzymePropSelector): ShallowWrapper<any, any>;
483 closest(selector: string): ShallowWrapper<HTMLAttributes, any>;
484
485 /**
486 * Returns a wrapper with the direct parent of the node in the current wrapper.
487 */
488 parent(): ShallowWrapper<any, any>;
489
490 /**
491 * Returns a wrapper of the node rendered by the provided render prop.
492 */
493 renderProp<PropName extends keyof P>(
494 prop: PropName,
495 ): (...params: Parameters<P[PropName]>) => ShallowWrapper<any, never>;
496
497 /**
498 * If a wrappingComponent was passed in options,
499 * this methods returns a ShallowWrapper around the rendered wrappingComponent.
500 * This ShallowWrapper can be used to update the wrappingComponent's props and state
501 */
502 getWrappingComponent: () => ShallowWrapper;
503}
504
505export interface ReactWrapper<P = {}, S = {}, C = Component> extends CommonWrapper<P, S, C> {}
506export class ReactWrapper<P = {}, S = {}, C = Component> {
507 constructor(nodes: JSX.Element | JSX.Element[], root?: ReactWrapper<any, any>, options?: MountRendererProps);
508
509 unmount(): this;
510 mount(): this;
511
512 /**
513 * Returns a wrapper of the node that matches the provided reference name.
514 *
515 * NOTE: can only be called on a wrapper instance that is also the root instance.
516 */
517 ref(refName: string): ReactWrapper<any, any>;
518 ref<P2, S2>(refName: string): ReactWrapper<P2, S2>;
519
520 /**
521 * Detaches the react tree from the DOM. Runs ReactDOM.unmountComponentAtNode() under the hood.
522 *
523 * This method will most commonly be used as a "cleanup" method if you decide to use the attachTo option in mount(node, options).
524 *
525 * The method is intentionally not "fluent" (in that it doesn't return this) because you should not be doing anything with this wrapper after this method is called.
526 *
527 * Using the attachTo is not generally recommended unless it is absolutely necessary to test something.
528 * It is your responsibility to clean up after yourself at the end of the test if you do decide to use it, though.
529 */
530 detach(): void;
531
532 /**
533 * Strips out all the not host-nodes from the list of nodes
534 *
535 * This method is useful if you want to check for the presence of host nodes
536 * (actually rendered HTML elements) ignoring the React nodes.
537 */
538 hostNodes(): ReactWrapper<HTMLAttributes>;
539
540 /**
541 * Find every node in the render tree that matches the provided selector.
542 * @param selector The selector to match.
543 */
544 find<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
545 find<P2>(component: ComponentType<P2>): ReactWrapper<P2, any>;
546 find<C2 extends Component>(componentClass: ComponentClass<C2['props']>): ReactWrapper<C2['props'], C2['state'], C2>;
547 find(props: EnzymePropSelector): ReactWrapper<any, any>;
548 find(selector: string): ReactWrapper<HTMLAttributes, any>;
549
550 /**
551 * Finds every node in the render tree that returns true for the provided predicate function.
552 */
553 findWhere(predicate: (wrapper: ReactWrapper<any, any>) => boolean): ReactWrapper<any, any>;
554
555 /**
556 * Removes nodes in the current wrapper that do not match the provided selector.
557 * @param selector The selector to match.
558 */
559 filter<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
560 filter<P2>(component: ComponentType<P2>): ReactWrapper<P2, any>;
561 filter(props: EnzymePropSelector | string): ReactWrapper<P, S>;
562
563 /**
564 * Returns a new wrapper with all of the children of the node(s) in the current wrapper. Optionally, a selector
565 * can be provided and it will filter the children by this selector.
566 */
567 children<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
568 children<P2>(component: ComponentType<P2>): ReactWrapper<P2, any>;
569 children(selector: string): ReactWrapper<HTMLAttributes, any>;
570 children(props?: EnzymePropSelector): ReactWrapper<any, any>;
571
572 /**
573 * Returns a new wrapper with child at the specified index.
574 */
575 childAt(index: number): ReactWrapper<any, any>;
576 childAt<P2, S2>(index: number): ReactWrapper<P2, S2>;
577
578 /**
579 * Returns a wrapper around all of the parents/ancestors of the wrapper. Does not include the node in the
580 * current wrapper. Optionally, a selector can be provided and it will filter the parents by this selector.
581 *
582 * Note: can only be called on a wrapper of a single node.
583 */
584 parents<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
585 parents<P2>(component: ComponentType<P2>): ReactWrapper<P2, any>;
586 parents(selector: string): ReactWrapper<HTMLAttributes, any>;
587 parents(props?: EnzymePropSelector): ReactWrapper<any, any>;
588
589 /**
590 * Returns a wrapper of the first element that matches the selector by traversing up through the current node's
591 * ancestors in the tree, starting with itself.
592 *
593 * Note: can only be called on a wrapper of a single node.
594 */
595 closest<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
596 closest<P2>(component: ComponentType<P2>): ReactWrapper<P2, any>;
597 closest(props: EnzymePropSelector): ReactWrapper<any, any>;
598 closest(selector: string): ReactWrapper<HTMLAttributes, any>;
599
600 /**
601 * Returns a wrapper with the direct parent of the node in the current wrapper.
602 */
603 parent(): ReactWrapper<any, any>;
604
605 /**
606 * If a wrappingComponent was passed in options,
607 * this methods returns a ReactWrapper around the rendered wrappingComponent.
608 * This ReactWrapper can be used to update the wrappingComponent's props and state
609 */
610 getWrappingComponent: () => ReactWrapper;
611}
612
613export interface Lifecycles {
614 componentDidUpdate?: {
615 onSetState: boolean;
616 prevContext: boolean;
617 } | undefined;
618 getDerivedStateFromProps?: { hasShouldComponentUpdateBug: boolean } | boolean | undefined;
619 getChildContext?: {
620 calledByRenderer: boolean;
621 [key: string]: any;
622 } | undefined;
623 setState?: any;
624 // TODO Maybe some life cycle are missing
625 [lifecycleName: string]: any;
626}
627
628export interface ShallowRendererProps {
629 // See https://github.com/airbnb/enzyme/blob/enzyme@3.10.0/docs/api/shallow.md#arguments
630 /**
631 * If set to true, componentDidMount is not called on the component, and componentDidUpdate is not called after
632 * setProps and setContext. Default to false.
633 */
634 disableLifecycleMethods?: boolean | undefined;
635 /**
636 * Enable experimental support for full react lifecycle methods
637 */
638 lifecycleExperimental?: boolean | undefined;
639 /**
640 * Context to be passed into the component
641 */
642 context?: any;
643 /**
644 * The legacy enableComponentDidUpdateOnSetState option should be matched by
645 * `lifecycles: { componentDidUpdate: { onSetState: true } }`, for compatibility
646 */
647 enableComponentDidUpdateOnSetState?: boolean | undefined;
648 /**
649 * the legacy supportPrevContextArgumentOfComponentDidUpdate option should be matched by
650 * `lifecycles: { componentDidUpdate: { prevContext: true } }`, for compatibility
651 */
652 supportPrevContextArgumentOfComponentDidUpdate?: boolean | undefined;
653 lifecycles?: Lifecycles | undefined;
654 /**
655 * A component that will render as a parent of the node.
656 * It can be used to provide context to the `node`, among other things.
657 * See the [getWrappingComponent() docs](https://airbnb.io/enzyme/docs/api/ShallowWrapper/getWrappingComponent.html) for an example.
658 * **Note**: `wrappingComponent` must render its children.
659 */
660 wrappingComponent?: ComponentType<any> | undefined;
661 /**
662 * Initial props to pass to the `wrappingComponent` if it is specified.
663 */
664 wrappingComponentProps?: {} | undefined;
665 /**
666 * If set to true, when rendering Suspense enzyme will replace all the lazy components in children
667 * with fallback element prop. Otherwise it won't handle fallback of lazy component.
668 * Default to true. Note: not supported in React < 16.6.
669 */
670 suspenseFallback?: boolean | undefined;
671 adapter?: EnzymeAdapter | undefined;
672 /* TODO what are these doing??? */
673 attachTo?: any;
674 hydrateIn?: any;
675 PROVIDER_VALUES?: any;
676}
677
678export interface MountRendererProps {
679 /**
680 * Context to be passed into the component
681 */
682 context?: {} | undefined;
683 /**
684 * DOM Element to attach the component to
685 */
686 attachTo?: HTMLElement | null | undefined;
687 /**
688 * Merged contextTypes for all children of the wrapper
689 */
690 childContextTypes?: {} | undefined;
691 /**
692 * A component that will render as a parent of the node.
693 * It can be used to provide context to the `node`, among other things.
694 * See the [getWrappingComponent() docs](https://airbnb.io/enzyme/docs/api/ShallowWrapper/getWrappingComponent.html) for an example.
695 * **Note**: `wrappingComponent` must render its children.
696 */
697 wrappingComponent?: ComponentType<any> | undefined;
698 /**
699 * Initial props to pass to the `wrappingComponent` if it is specified.
700 */
701 wrappingComponentProps?: {} | undefined;
702}
703
704/**
705 * Shallow rendering is useful to constrain yourself to testing a component as a unit, and to ensure that
706 * your tests aren't indirectly asserting on behavior of child components.
707 */
708export function shallow<C extends Component, P = C['props'], S = C['state']>(
709 node: ReactElement<P>,
710 options?: ShallowRendererProps,
711): ShallowWrapper<P, S, C>;
712export function shallow<P>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, any>;
713export function shallow<P, S>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, S>;
714
715/**
716 * Mounts and renders a react component into the document and provides a testing wrapper around it.
717 */
718export function mount<C extends Component, P = C['props'], S = C['state']>(
719 node: ReactElement<P>,
720 options?: MountRendererProps,
721): ReactWrapper<P, S, C>;
722export function mount<P>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, any>;
723export function mount<P, S>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, S>;
724
725/**
726 * Render react components to static HTML and analyze the resulting HTML structure.
727 */
728export function render<P, S>(node: ReactElement<P>, options?: any): cheerio.Cheerio;
729
730// See https://github.com/airbnb/enzyme/blob/v3.10.0/packages/enzyme/src/EnzymeAdapter.js
731export class EnzymeAdapter {
732 wrapWithWrappingComponent?: ((node: ReactElement, options?: ShallowRendererProps) => any) | undefined;
733}
734
735/**
736 * Configure enzyme to use the correct adapter for the react version
737 * This is enabling the Enzyme configuration with adapters in TS
738 */
739export function configure(options: {
740 adapter: EnzymeAdapter;
741 // See https://github.com/airbnb/enzyme/blob/enzyme@3.10.0/docs/guides/migration-from-2-to-3.md#lifecycle-methods
742 // Actually, `{adapter:} & Pick<ShallowRendererProps,"disableLifecycleMethods">` is more precise. However,
743 // in that case jsdoc won't be shown
744 /**
745 * If set to true, componentDidMount is not called on the component, and componentDidUpdate is not called after
746 * setProps and setContext. Default to false.
747 */
748 disableLifecycleMethods?: boolean | undefined;
749}): void;
750
\No newline at end of file