diff --git a/types/enzyme/enzyme-tests.tsx b/types/enzyme/enzyme-tests.tsx index 87b4d032e8..14cfd6443c 100644 --- a/types/enzyme/enzyme-tests.tsx +++ b/types/enzyme/enzyme-tests.tsx @@ -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(Component: ComponentClass | StatelessComponent): ComponentClass | StatelessComponent { return Component; } @@ -59,6 +63,8 @@ class AnotherComponent extends Component { } } +class MyRenderPropComponent extends Component {} + const MyStatelessComponent = (props: StatelessProps) => ; const AnotherStatelessComponent = (props: AnotherStatelessProps) => ; @@ -477,6 +483,11 @@ function ShallowWrapperTest() { shallowWrapper = new ShallowWrapper(, undefined, { lifecycleExperimental: true }); shallowWrapper = new ShallowWrapper(, shallowWrapper, { lifecycleExperimental: true }); } + + function test_renderProp() { + let shallowWrapper = new ShallowWrapper(
} />); + shallowWrapper = shallowWrapper.renderProp('children')('test'); + } } // ReactWrapper diff --git a/types/enzyme/index.d.ts b/types/enzyme/index.d.ts index 257beb21fc..afea55fdaa 100644 --- a/types/enzyme/index.d.ts +++ b/types/enzyme/index.d.ts @@ -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 // Cap3 @@ -8,6 +8,7 @@ // MartynasZilinskas // Torgeir Hovden // Martin Hochel +// Christian Rackerseder // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -447,6 +448,11 @@ export class ShallowWrapper

{ * Returns a wrapper with the direct parent of the node in the current wrapper. */ parent(): ShallowWrapper; + + /** + * Returns a wrapper of the node rendered by the provided render prop. + */ + renderProp(prop: PropName): (...params: any[]) => ShallowWrapper; } // tslint:disable-next-line no-empty-interface