mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-08 09:17:06 +08:00
enzyme: Fix lint (#20855)
This commit is contained in:
56
types/enzyme/index.d.ts
vendored
56
types/enzyme/index.d.ts
vendored
@@ -48,31 +48,26 @@ export type Intercepter<T> = (intercepter: T) => void;
|
||||
export interface CommonWrapper<P = {}, S = {}> {
|
||||
/**
|
||||
* Returns a new wrapper with only the nodes of the current wrapper that, when passed into the provided predicate function, return true.
|
||||
* @param predicate
|
||||
*/
|
||||
filterWhere(predicate: (wrapper: this) => boolean): this;
|
||||
|
||||
/**
|
||||
* Returns whether or not the current wrapper has a node anywhere in it's render tree that looks like the one passed in.
|
||||
* @param node
|
||||
*/
|
||||
contains(node: ReactElement<any> | string): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not a given react element exists in the shallow render tree.
|
||||
* @param node
|
||||
*/
|
||||
containsMatchingElement(node: ReactElement<any>): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not all the given react elements exists in the shallow render tree
|
||||
* @param nodes
|
||||
*/
|
||||
containsAllMatchingElements(nodes: Array<ReactElement<any>>): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not one of the given react elements exists in the shallow render tree.
|
||||
* @param nodes
|
||||
*/
|
||||
containsAnyMatchingElements(nodes: Array<ReactElement<any>>): boolean;
|
||||
|
||||
@@ -88,13 +83,11 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
|
||||
/**
|
||||
* Returns whether or not the current node has a className prop including the passed in class name.
|
||||
* @param className
|
||||
*/
|
||||
hasClass(className: string): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not the current node matches a provided selector.
|
||||
* @param selector
|
||||
*/
|
||||
is(selector: EnzymeSelector): boolean;
|
||||
|
||||
@@ -112,7 +105,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
/**
|
||||
* Returns a new wrapper with only the nodes of the current wrapper that don't match the provided selector.
|
||||
* This method is effectively the negation or inverse of filter.
|
||||
* @param selector
|
||||
*/
|
||||
not(selector: EnzymeSelector): this;
|
||||
|
||||
@@ -134,7 +126,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
|
||||
/**
|
||||
* Returns the node at a given index of the current wrapper.
|
||||
* @param index
|
||||
*/
|
||||
get(index: number): ReactElement<any>;
|
||||
|
||||
@@ -165,7 +156,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
|
||||
/**
|
||||
* Returns a wrapper around the node at a given index of the current wrapper.
|
||||
* @param index
|
||||
*/
|
||||
at(index: number): this;
|
||||
|
||||
@@ -191,7 +181,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
|
||||
/**
|
||||
* Returns the state hash for the root node of the wrapper. Optionally pass in a prop name and it will return just that value.
|
||||
* @param [key]
|
||||
*/
|
||||
state(): S;
|
||||
state<K extends keyof S>(key: K): S[K];
|
||||
@@ -214,7 +203,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
* Returns the prop value for the node of the current wrapper with the provided key.
|
||||
*
|
||||
* NOTE: can only be called on a wrapper of a single node.
|
||||
* @param key
|
||||
*/
|
||||
prop<K extends keyof P>(key: K): P[K];
|
||||
prop<T>(key: string): T;
|
||||
@@ -228,7 +216,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
/**
|
||||
* Simulate events.
|
||||
* Returns itself.
|
||||
* @param event
|
||||
* @param args?
|
||||
*/
|
||||
simulate(event: string, ...args: any[]): this;
|
||||
@@ -242,8 +229,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
* Returns itself.
|
||||
*
|
||||
* NOTE: can only be called on a wrapper instance that is also the root instance.
|
||||
* @param state
|
||||
* @param [callback]
|
||||
*/
|
||||
setState<K extends keyof S>(state: Pick<S, K>, callback?: () => void): this;
|
||||
|
||||
@@ -256,7 +241,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
* Returns itself.
|
||||
*
|
||||
* NOTE: can only be called on a wrapper instance that is also the root instance.
|
||||
* @param props
|
||||
*/
|
||||
setProps<K extends keyof P>(props: Pick<P, K>): this;
|
||||
|
||||
@@ -266,7 +250,6 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
* Returns itself.
|
||||
*
|
||||
* NOTE: can only be called on a wrapper instance that is also the root instance.
|
||||
* @param state
|
||||
*/
|
||||
setContext(context: any): this;
|
||||
|
||||
@@ -320,40 +303,32 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
/**
|
||||
* Applies the provided reducing function to every node in the wrapper to reduce to a single value. Each node
|
||||
* is passed in as a ShallowWrapper, and is processed from left to right.
|
||||
* @param fn
|
||||
* @param initialValue
|
||||
*/
|
||||
reduce<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R;
|
||||
|
||||
/**
|
||||
* Applies the provided reducing function to every node in the wrapper to reduce to a single value.
|
||||
* Each node is passed in as a ShallowWrapper, and is processed from right to left.
|
||||
* @param fn
|
||||
* @param initialValue
|
||||
*/
|
||||
reduceRight<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R;
|
||||
|
||||
/**
|
||||
* Returns whether or not any of the nodes in the wrapper match the provided selector.
|
||||
* @param selector
|
||||
*/
|
||||
some(selector: EnzymeSelector): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not any of the nodes in the wrapper pass the provided predicate function.
|
||||
* @param fn
|
||||
*/
|
||||
someWhere(fn: (wrapper: this) => boolean): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not all of the nodes in the wrapper match the provided selector.
|
||||
* @param selector
|
||||
*/
|
||||
every(selector: EnzymeSelector): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not all of the nodes in the wrapper pass the provided predicate function.
|
||||
* @param fn
|
||||
*/
|
||||
everyWhere(fn: (wrapper: this) => boolean): boolean;
|
||||
|
||||
@@ -378,11 +353,9 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
length: number;
|
||||
}
|
||||
|
||||
export class ShallowWrapper {
|
||||
export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {}
|
||||
export class ShallowWrapper<P = {}, S = {}> {
|
||||
constructor(nodes: JSX.Element[] | JSX.Element, root?: ShallowWrapper, options?: ShallowRendererProps);
|
||||
}
|
||||
|
||||
export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
shallow(options?: ShallowRendererProps): ShallowWrapper<P, S>;
|
||||
unmount(): this;
|
||||
|
||||
@@ -404,14 +377,12 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
|
||||
/**
|
||||
* Finds every node in the render tree that returns true for the provided predicate function.
|
||||
* @param predicate
|
||||
*/
|
||||
findWhere(predicate: (wrapper: ShallowWrapper<any, any>) => boolean): ShallowWrapper<any, any>;
|
||||
|
||||
/**
|
||||
* Returns a new wrapper with all of the children of the node(s) in the current wrapper. Optionally, a selector
|
||||
* can be provided and it will filter the children by this selector.
|
||||
* @param [selector]
|
||||
*/
|
||||
children<P2>(component: ComponentClass<P2>): ShallowWrapper<P2, any>;
|
||||
children<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
|
||||
@@ -420,7 +391,6 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
|
||||
/**
|
||||
* Returns a new wrapper with child at the specified index.
|
||||
* @param index
|
||||
*/
|
||||
childAt(index: number): ShallowWrapper<any, any>;
|
||||
childAt<P2, S2>(index: number): ShallowWrapper<P2, S2>;
|
||||
@@ -428,7 +398,6 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
/**
|
||||
* Shallow render the one non-DOM child of the current wrapper, and return a wrapper around the result.
|
||||
* NOTE: can only be called on wrapper of a single non-DOM component element node.
|
||||
* @param [options]
|
||||
*/
|
||||
dive<P2, S2>(options?: ShallowRendererProps): ShallowWrapper<P2, S2>;
|
||||
|
||||
@@ -445,7 +414,6 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
* current wrapper. Optionally, a selector can be provided and it will filter the parents by this selector.
|
||||
*
|
||||
* Note: can only be called on a wrapper of a single node.
|
||||
* @param [selector]
|
||||
*/
|
||||
parents<P2>(component: ComponentClass<P2>): ShallowWrapper<P2, any>;
|
||||
parents<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
|
||||
@@ -457,7 +425,6 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
* ancestors in the tree, starting with itself.
|
||||
*
|
||||
* Note: can only be called on a wrapper of a single node.
|
||||
* @param selector
|
||||
*/
|
||||
closest<P2>(component: ComponentClass<P2>): ShallowWrapper<P2, any>;
|
||||
closest<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
|
||||
@@ -470,11 +437,10 @@ export interface ShallowWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
parent(): ShallowWrapper<any, any>;
|
||||
}
|
||||
|
||||
export class ReactWrapper {
|
||||
export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {}
|
||||
export class ReactWrapper<P = {}, S = {}> {
|
||||
constructor(nodes: JSX.Element | JSX.Element[], root?: ReactWrapper, options?: MountRendererProps);
|
||||
}
|
||||
|
||||
export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
unmount(): this;
|
||||
mount(): this;
|
||||
|
||||
@@ -517,7 +483,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
|
||||
/**
|
||||
* Finds every node in the render tree that returns true for the provided predicate function.
|
||||
* @param predicate
|
||||
*/
|
||||
findWhere(predicate: (wrapper: ReactWrapper<any, any>) => boolean): ReactWrapper<any, any>;
|
||||
|
||||
@@ -531,7 +496,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
/**
|
||||
* Returns a new wrapper with all of the children of the node(s) in the current wrapper. Optionally, a selector
|
||||
* can be provided and it will filter the children by this selector.
|
||||
* @param [selector]
|
||||
*/
|
||||
children<P2>(component: ComponentClass<P2>): ReactWrapper<P2, any>;
|
||||
children<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
|
||||
@@ -540,7 +504,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
|
||||
/**
|
||||
* Returns a new wrapper with child at the specified index.
|
||||
* @param index
|
||||
*/
|
||||
childAt(index: number): ReactWrapper<any, any>;
|
||||
childAt<P2, S2>(index: number): ReactWrapper<P2, S2>;
|
||||
@@ -550,7 +513,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
* current wrapper. Optionally, a selector can be provided and it will filter the parents by this selector.
|
||||
*
|
||||
* Note: can only be called on a wrapper of a single node.
|
||||
* @param [selector]
|
||||
*/
|
||||
parents<P2>(component: ComponentClass<P2>): ReactWrapper<P2, any>;
|
||||
parents<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
|
||||
@@ -562,7 +524,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
* ancestors in the tree, starting with itself.
|
||||
*
|
||||
* Note: can only be called on a wrapper of a single node.
|
||||
* @param selector
|
||||
*/
|
||||
closest<P2>(component: ComponentClass<P2>): ReactWrapper<P2, any>;
|
||||
closest<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
|
||||
@@ -583,8 +544,6 @@ export interface ReactWrapper<P = {}, S = {}> extends CommonWrapper<P, S> {
|
||||
* Returns itself.
|
||||
*
|
||||
* NOTE: can only be called on a wrapper instance that is also the root instance.
|
||||
* @param props
|
||||
* @param [callback]
|
||||
*/
|
||||
setProps<K extends keyof P>(props: Pick<P, K>, callback?: () => void): this;
|
||||
}
|
||||
@@ -618,24 +577,18 @@ export interface MountRendererProps {
|
||||
/**
|
||||
* Shallow rendering is useful to constrain yourself to testing a component as a unit, and to ensure that
|
||||
* your tests aren't indirectly asserting on behavior of child components.
|
||||
* @param node
|
||||
* @param [options]
|
||||
*/
|
||||
export function shallow<P>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, any>;
|
||||
export function shallow<P, S>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, S>;
|
||||
|
||||
/**
|
||||
* Mounts and renders a react component into the document and provides a testing wrapper around it.
|
||||
* @param node
|
||||
* @param [options]
|
||||
*/
|
||||
export function mount<P>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, any>;
|
||||
export function mount<P, S>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, S>;
|
||||
|
||||
/**
|
||||
* Render react components to static HTML and analyze the resulting HTML structure.
|
||||
* @param node
|
||||
* @param [options]
|
||||
*/
|
||||
export function render<P, S>(node: ReactElement<P>, options?: any): Cheerio;
|
||||
|
||||
@@ -646,6 +599,5 @@ export class EnzymeAdapter {
|
||||
/**
|
||||
* Configure enzyme to use the correct adapter for the react verstion
|
||||
* This is enabling the Enzyme configuration with adapters in TS
|
||||
* @param options
|
||||
*/
|
||||
export function configure(options: { adapter: EnzymeAdapter }): void;
|
||||
|
||||
Reference in New Issue
Block a user