UNPKG

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