mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
[enzyme] Add renderProp() function
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
ShallowRendererProps,
|
||||
ComponentClass as EnzymeComponentClass
|
||||
} from "enzyme";
|
||||
import { Component, ReactElement, HTMLAttributes, ComponentClass, StatelessComponent } from "react";
|
||||
import { Component, ReactElement, ReactNode, HTMLAttributes, ComponentClass, StatelessComponent } from "react";
|
||||
|
||||
// Help classes/interfaces
|
||||
interface MyComponentProps {
|
||||
@@ -35,6 +35,10 @@ interface MyComponentState {
|
||||
stateProperty: string;
|
||||
}
|
||||
|
||||
interface MyRenderPropProps {
|
||||
children: (params: string) => ReactNode;
|
||||
}
|
||||
|
||||
function toComponentType<T>(Component: ComponentClass<T> | StatelessComponent<T>): ComponentClass<T> | StatelessComponent<T> {
|
||||
return Component;
|
||||
}
|
||||
@@ -59,6 +63,8 @@ class AnotherComponent extends Component<AnotherComponentProps> {
|
||||
}
|
||||
}
|
||||
|
||||
class MyRenderPropComponent extends Component<MyRenderPropProps> {}
|
||||
|
||||
const MyStatelessComponent = (props: StatelessProps) => <span />;
|
||||
|
||||
const AnotherStatelessComponent = (props: AnotherStatelessProps) => <span />;
|
||||
@@ -477,6 +483,11 @@ function ShallowWrapperTest() {
|
||||
shallowWrapper = new ShallowWrapper<MyComponentProps, MyComponentState>(<MyComponent stringProp="1" numberProp={1} />, undefined, { lifecycleExperimental: true });
|
||||
shallowWrapper = new ShallowWrapper<MyComponentProps, MyComponentState>(<MyComponent stringProp="1" numberProp={1} />, shallowWrapper, { lifecycleExperimental: true });
|
||||
}
|
||||
|
||||
function test_renderProp() {
|
||||
let shallowWrapper = new ShallowWrapper<MyRenderPropProps>(<MyRenderPropComponent children={(params) => <div className={params} />} />);
|
||||
shallowWrapper = shallowWrapper.renderProp('children')('test');
|
||||
}
|
||||
}
|
||||
|
||||
// ReactWrapper
|
||||
|
||||
Vendored
+7
-1
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Enzyme 3.1
|
||||
// Type definitions for Enzyme 3.9
|
||||
// Project: https://github.com/airbnb/enzyme
|
||||
// Definitions by: Marian Palkus <https://github.com/MarianPalkus>
|
||||
// Cap3 <http://www.cap3.de>
|
||||
@@ -8,6 +8,7 @@
|
||||
// MartynasZilinskas <https://github.com/MartynasZilinskas>
|
||||
// Torgeir Hovden <https://github.com/thovden>
|
||||
// Martin Hochel <https://github.com/hotell>
|
||||
// Christian Rackerseder <https://github.com/screendriver>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -447,6 +448,11 @@ export class ShallowWrapper<P = {}, S = {}, C = Component> {
|
||||
* Returns a wrapper with the direct parent of the node in the current wrapper.
|
||||
*/
|
||||
parent(): ShallowWrapper<any, any>;
|
||||
|
||||
/**
|
||||
* Returns a wrapper of the node rendered by the provided render prop.
|
||||
*/
|
||||
renderProp<PropName extends keyof P>(prop: PropName): (...params: any[]) => ShallowWrapper<P, S>;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line no-empty-interface
|
||||
|
||||
Reference in New Issue
Block a user