Enzyme: .filter(selector) returns this

add strongly typed prop selector for filter
This commit is contained in:
Justin Bay 2017-02-02 19:14:32 -05:00
parent b03ba92736
commit 0ae246ab30
2 changed files with 10 additions and 12 deletions

View File

@ -60,8 +60,8 @@ namespace ShallowWrapperTest {
function test_filter() {
shallowWrapper = shallowWrapper.filter(MyComponent);
statelessWrapper = shallowWrapper.filter(MyStatelessComponent);
shallowWrapper = shallowWrapper.filter({ prop: 'value' });
statelessWrapper = statelessWrapper.filter(MyStatelessComponent);
shallowWrapper = shallowWrapper.filter({ numberProp: 12 });
elementWrapper = shallowWrapper.filter('.selector');
}
@ -384,8 +384,8 @@ namespace ReactWrapperTest {
function test_filter() {
reactWrapper = reactWrapper.filter(MyComponent);
statelessWrapper = reactWrapper.filter(MyStatelessComponent);
reactWrapper = reactWrapper.filter({ prop: 'myprop' });
statelessWrapper = statelessWrapper.filter(MyStatelessComponent);
reactWrapper = reactWrapper.filter({ numberProp: 12 });
elementWrapper = reactWrapper.filter('.selector');
}

14
enzyme/index.d.ts vendored
View File

@ -352,10 +352,9 @@ export interface ShallowWrapper<P, S> extends CommonWrapper<P, S> {
* Removes nodes in the current wrapper that do not match the provided selector.
* @param selector The selector to match.
*/
filter<P2>(component: ComponentClass<P2>): ShallowWrapper<P2, any>;
filter<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, never>;
filter(props: EnzymePropSelector): ShallowWrapper<any, any>;
filter(selector: string): ShallowWrapper<HTMLAttributes, any>;
filter<P2>(component: ComponentClass<P2> | StatelessComponent<P2>): this;
filter(props: Partial<P>): this;
filter(selector: string): this;
/**
* Finds every node in the render tree that returns true for the provided predicate function.
@ -459,10 +458,9 @@ export interface ReactWrapper<P, S> extends CommonWrapper<P, S> {
* Removes nodes in the current wrapper that do not match the provided selector.
* @param selector The selector to match.
*/
filter<P2>(component: ComponentClass<P2>): ReactWrapper<P2, any>;
filter<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, never>;
filter(props: EnzymePropSelector): ReactWrapper<any, any>;
filter(selector: string): ReactWrapper<HTMLAttributes, any>;
filter<P2>(component: ComponentClass<P2> | StatelessComponent<P2>): this;
filter(props: Partial<P>): this;
filter(selector: string): this;
/**
* Returns a new wrapper with all of the children of the node(s) in the current wrapper. Optionally, a selector