/// /// import React = require('react'); import test = require('blue-tape'); import recompose = require('recompose'); // GIVEN interface StatelessCmpProps { bar: string; } const StatelessCmp: React.StatelessComponent = (props: StatelessCmpProps): JSX.Element => { return
{ props.bar }
; }; interface CmpProps { nProp: number; sProp: string; } interface CmpState { s1: number; s2: string; } class Cmp extends React.Component { public render(): JSX.Element { return
{ this.props.nProp }
; } } test('withContext', t => { const { withContext } = recompose; t.equal(typeof withContext, 'function', 'withContext is a function'); const withContextFactory = withContext( { fooFn: React.PropTypes.object }, () => ({ fooFn: () => { } }) ); const StatelessCmpContainsContext = withContextFactory(StatelessCmp); // // TS2324: Property 'bar' is missing in type ... ; const CmpContainsContext = withContextFactory(Cmp); // // Property 'nProp' is missing in type ... // Property 'sProp' is missing in type ... ; return t.end(); }); test('mapProps', t => { const { mapProps } = recompose; t.equal(typeof mapProps, 'function', 'mapProps is a function'); interface NeededProps { firstName: string; lastName: string; } interface MappedProps { fullName: string; } class FullName extends React.Component { render() { return
{ this.props.fullName }
; } } const propMapper = mapProps((props: NeededProps) => ({ fullName: props.firstName + ' ' + props.lastName })); const FirstAndLastName = propMapper(FullName); // // {firstName|lastName} is missing in type ... ; return t.end(); }); test('withProps', t => { t.equal(typeof recompose.withProps, 'function', 'withProps is a function'); const withPropsFactory = recompose.withProps((props: CmpProps) => ({ sAdditionalProp: 'foo' })); const CmpWithAdditionalProp = withPropsFactory(Cmp); // // TS2324: Property 'sAdditionalProp' is missing in type ... ; return t.end(); }); test('pure', t => { t.equal(typeof recompose.pure, 'function', 'pure is a function'); const PureStatelessCmp = recompose.pure(StatelessCmp); const PureCmp = recompose.pure(Cmp); // ; // TS2324: Property 'bar' is missing in type ... ; // ; // Property 'nProp' is missing in type ... // Property 'sProp' is missing in type ... ; return t.end(); }); test('setPropTypes', t => { t.equal(typeof recompose.withProps, 'function', 'withProps is a function'); interface TheOnlyProperty { theOnlyProperty: string; } const setPropTypesFactory = recompose.setPropTypes({ theOnlyProperty: React.PropTypes.string } as React.ValidationMap); const CmpWithTheOnlyProperty = setPropTypesFactory(Cmp); // // Property 'theOnlyProperty' is missing in type ; return t.end(); }); test('getContext', t => { t.equal(typeof recompose.getContext, 'function', 'getContext is a function'); interface PropsFromContext { propFromContext: string; } const getContextFactory = recompose.getContext({ propFromContext: React.PropTypes.string, }); const CmpWithContext = getContextFactory(Cmp) as React.ComponentClass; // // Property 'nProp' is missing in type ... // Property 'sProp' is missing in type ... // Property 'propFromContext' is missing in type ... ; return t.end(); }); test('componentFromProp', t => { const Div =
; interface ButtonProps { component: string | JSX.Element; } t.equal(typeof recompose.componentFromProp, 'function', 'componentFromProp is a function'); const Button = recompose.componentFromProp('component');