|
| 1 | +// flow-typed signature: 931d5482afcb022bcbddb841fd08d683 |
| 2 | +// flow-typed version: 5175c53189/enzyme_v3.x.x/flow_>=v0.104.x |
| 3 | + |
| 4 | +declare module "enzyme" { |
| 5 | + declare type PredicateFunction<T: Wrapper<*>> = ( |
| 6 | + wrapper: T, |
| 7 | + index: number |
| 8 | + ) => boolean; |
| 9 | + declare type UntypedSelector = string | { [key: string]: number|string|boolean, ... }; |
| 10 | + declare type EnzymeSelector = UntypedSelector | React$ElementType; |
| 11 | + |
| 12 | + // CheerioWrapper is a type alias for an actual cheerio instance |
| 13 | + // TODO: Reference correct type from cheerio's type declarations |
| 14 | + declare type CheerioWrapper = any; |
| 15 | + |
| 16 | + declare class Wrapper<RootComponent> { |
| 17 | + equals(node: React$Element<any>): boolean, |
| 18 | + find(selector: UntypedSelector): this, |
| 19 | + find<T: React$ElementType>(selector: T): ReactWrapper<T>, |
| 20 | + findWhere(predicate: PredicateFunction<this>): this, |
| 21 | + filter(selector: UntypedSelector): this, |
| 22 | + filter<T: React$ElementType>(selector: T): ReactWrapper<T>, |
| 23 | + filterWhere(predicate: PredicateFunction<this>): this, |
| 24 | + hostNodes(): this, |
| 25 | + contains(nodes: React$Node): boolean, |
| 26 | + containsMatchingElement(node: React$Node): boolean, |
| 27 | + containsAllMatchingElements(nodes: React$Node): boolean, |
| 28 | + containsAnyMatchingElements(nodes: React$Node): boolean, |
| 29 | + dive(option?: { context?: Object, ... }): this, |
| 30 | + exists(selector?: EnzymeSelector): boolean, |
| 31 | + isEmptyRender(): boolean, |
| 32 | + matchesElement(node: React$Node): boolean, |
| 33 | + hasClass(className: string): boolean, |
| 34 | + is(selector: EnzymeSelector): boolean, |
| 35 | + isEmpty(): boolean, |
| 36 | + not(selector: EnzymeSelector): this, |
| 37 | + children(selector?: UntypedSelector): this, |
| 38 | + children<T: React$ElementType>(selector: T): ReactWrapper<T>, |
| 39 | + childAt(index: number): this, |
| 40 | + parents(selector?: UntypedSelector): this, |
| 41 | + parents<T: React$ElementType>(selector: T): ReactWrapper<T>, |
| 42 | + parent(): this, |
| 43 | + closest(selector: UntypedSelector): this, |
| 44 | + closest<T: React$ElementType>(selector: T): ReactWrapper<T>, |
| 45 | + render(): CheerioWrapper, |
| 46 | + renderProp(propName: string): (...args: Array<any>) => this, |
| 47 | + unmount(): this, |
| 48 | + text(): string, |
| 49 | + html(): string, |
| 50 | + invoke(propName: string): (...args: $ReadOnlyArray<any>) => mixed, |
| 51 | + get(index: number): React$Node, |
| 52 | + getDOMNode(): HTMLElement | HTMLInputElement, |
| 53 | + at(index: number): this, |
| 54 | + first(): this, |
| 55 | + last(): this, |
| 56 | + state(key?: string): any, |
| 57 | + context(key?: string): any, |
| 58 | + props(): Object, |
| 59 | + prop(key: string): any, |
| 60 | + key(): string, |
| 61 | + simulate(event: string, ...args: Array<any>): this, |
| 62 | + simulateError(error: Error): this, |
| 63 | + slice(begin?: number, end?: number): this, |
| 64 | + setState(state: {...}, callback?: () => void): this, |
| 65 | + setProps(props: {...}, callback?: () => void): this, |
| 66 | + setContext(context: Object): this, |
| 67 | + instance(): React$ElementRef<RootComponent>, |
| 68 | + update(): this, |
| 69 | + debug(options?: Object): string, |
| 70 | + type(): string | Function | null, |
| 71 | + name(): string, |
| 72 | + forEach(fn: (node: this, index: number) => mixed): this, |
| 73 | + map<T>(fn: (node: this, index: number) => T): Array<T>, |
| 74 | + reduce<T>( |
| 75 | + fn: (value: T, node: this, index: number) => T, |
| 76 | + initialValue?: T |
| 77 | + ): Array<T>, |
| 78 | + reduceRight<T>( |
| 79 | + fn: (value: T, node: this, index: number) => T, |
| 80 | + initialValue?: T |
| 81 | + ): Array<T>, |
| 82 | + some(selector: EnzymeSelector): boolean, |
| 83 | + someWhere(predicate: PredicateFunction<this>): boolean, |
| 84 | + every(selector: EnzymeSelector): boolean, |
| 85 | + everyWhere(predicate: PredicateFunction<this>): boolean, |
| 86 | + length: number |
| 87 | + } |
| 88 | + |
| 89 | + declare class ReactWrapper<T> extends Wrapper<T> { |
| 90 | + constructor(nodes: React$Element<T>, root: any, options?: ?Object): ReactWrapper<T>, |
| 91 | + mount(): this, |
| 92 | + ref(refName: string): this, |
| 93 | + detach(): void |
| 94 | + } |
| 95 | + |
| 96 | + declare class ShallowWrapper<T> extends Wrapper<T> { |
| 97 | + constructor( |
| 98 | + nodes: React$Element<T>, |
| 99 | + root: any, |
| 100 | + options?: ?Object |
| 101 | + ): ShallowWrapper<T>, |
| 102 | + equals(node: React$Node): boolean, |
| 103 | + shallow(options?: { context?: Object, ... }): ShallowWrapper<T>, |
| 104 | + getElement(): React$Node, |
| 105 | + getElements(): Array<React$Node> |
| 106 | + } |
| 107 | + |
| 108 | + declare function shallow<T>( |
| 109 | + node: React$Element<T>, |
| 110 | + options?: { |
| 111 | + context?: Object, |
| 112 | + disableLifecycleMethods?: boolean, |
| 113 | + ... |
| 114 | + } |
| 115 | + ): ShallowWrapper<T>; |
| 116 | + declare function mount<T>( |
| 117 | + node: React$Element<T>, |
| 118 | + options?: { |
| 119 | + context?: Object, |
| 120 | + attachTo?: HTMLElement, |
| 121 | + childContextTypes?: Object, |
| 122 | + ... |
| 123 | + } |
| 124 | + ): ReactWrapper<T>; |
| 125 | + declare function render( |
| 126 | + node: React$Node, |
| 127 | + options?: { context?: Object, ... } |
| 128 | + ): CheerioWrapper; |
| 129 | + |
| 130 | + declare module.exports: { |
| 131 | + configure(options: { |
| 132 | + Adapter?: any, |
| 133 | + disableLifecycleMethods?: boolean, |
| 134 | + ... |
| 135 | + }): void, |
| 136 | + render: typeof render, |
| 137 | + mount: typeof mount, |
| 138 | + shallow: typeof shallow, |
| 139 | + ShallowWrapper: typeof ShallowWrapper, |
| 140 | + ReactWrapper: typeof ReactWrapper, |
| 141 | + ... |
| 142 | + }; |
| 143 | +} |
0 commit comments