@@ -23,40 +23,57 @@ test('return one component with children props as function', () => {
2323} )
2424
2525test ( 'rendering children component' , ( ) => {
26- const Foo = ( { children } ) =>
27- children && typeof children === 'function' && children ( 'foo' )
26+ const Foo = ( { children, tor } ) =>
27+ children && typeof children === 'function' && children ( tor + 'foo' )
2828
29- const Bar = ( { children } ) =>
30- children && typeof children === 'function' && children ( 'bar' )
29+ const Bar = ( { render , tor } ) =>
30+ render && typeof render === 'function' && render ( tor + 'bar' )
3131
3232 interface RenderProps {
3333 foo : 'foo'
3434 bar : 'bar'
3535 }
3636
37- const Composed = adopt < RenderProps > ( {
38- bar : < Bar /> ,
39- foo : < Foo /> ,
37+ interface Props {
38+ tor : string
39+ }
40+
41+ const Composed = adopt < RenderProps , Props > ( {
42+ bar : ( { tor, render } ) => < Bar tor = { tor } render = { render } /> ,
43+ foo : ( { tor, render } ) => < Foo tor = { tor } > { render } </ Foo > ,
4044 } )
4145
4246 const result = shallow (
43- < Composed >
47+ < Composed tor = "tor" >
4448 { props => (
4549 < div >
46- { props . foo }
47- { props . bar }
50+ < div > { props . foo } </ div >
51+ < div > { props . bar } </ div >
4852 </ div >
4953 ) }
5054 </ Composed >
5155 )
5256
5357 expect ( result . children ( ) . length ) . toBe ( 1 )
54- expect ( result . html ( ) ) . toBe ( '<div>foobar </div>' )
58+ expect ( result . html ( ) ) . toBe ( '<div><div>torfoo</div><div>torbar</div> </div>' )
5559} )
5660
57- test ( 'should allow a function as mapper ' , ( ) => {
61+ test ( 'passing a function' , ( ) => {
5862 const Foo = ( { children } ) => children ( 'foo' )
59- const foo = jest . fn ( ( { renderProp } ) => < Foo children = { renderProp } /> )
63+ const foo = jest . fn ( ( { render } ) => < Foo > { render } </ Foo > )
64+ const children = jest . fn ( ( ) => null )
65+ const Composed = adopt ( { foo } )
66+
67+ mount ( < Composed > { children } </ Composed > )
68+
69+ expect ( foo ) . toHaveBeenCalled ( )
70+ expect ( children ) . toHaveBeenCalledWith ( { foo : 'foo' } )
71+ } )
72+
73+ test ( 'passing a function changing the render prop on mapper' , ( ) => {
74+ const Foo = ( { render } ) => render ( 'foo' )
75+
76+ const foo = jest . fn ( ( { render } ) => < Foo render = { render } /> )
6077 const children = jest . fn ( ( ) => null )
6178 const Composed = adopt ( { foo } )
6279
@@ -69,7 +86,7 @@ test('should allow a function as mapper', () => {
6986test ( 'should provide a function mapper with all previous render prop results' , ( ) => {
7087 const Foo = ( { children } ) => children ( 'foo' )
7188 const Bar = ( { children } ) => children ( 'bar' )
72- const bar = jest . fn ( ( { renderProp } ) => < Bar children = { renderProp } / >)
89+ const bar = jest . fn ( ( { render } ) => < Bar > { render } </ Bar > )
7390 const children = jest . fn ( ( ) => null )
7491
7592 interface RenderProps {
@@ -90,9 +107,20 @@ test('should provide a function mapper with all previous render prop results', (
90107
91108test ( 'should provide mapper functions with Composed component props' , ( ) => {
92109 const Foo = ( { children } ) => children ( 'foo' )
93- const foo = jest . fn ( ( { renderProp } ) => < Foo children = { renderProp } / >)
110+ const foo = jest . fn ( ( { render } ) => < Foo > { render } </ Foo > )
94111 const children = jest . fn ( ( ) => null )
95- const Composed = adopt ( { foo } )
112+
113+ type RenderProps = {
114+ foo : string
115+ }
116+
117+ type Props = {
118+ bar : string
119+ }
120+
121+ const Composed = adopt < RenderProps , Props > ( {
122+ foo,
123+ } )
96124
97125 mount ( < Composed bar = "bar" > { children } </ Composed > )
98126
@@ -102,8 +130,8 @@ test('should provide mapper functions with Composed component props', () => {
102130
103131test ( 'throw with a wrong value on mapper' , ( ) => {
104132 expect ( ( ) => {
105- const Composed = adopt ( { foo : 'helo' } )
106- return shallow ( < Composed > { props => < div > { props . foo } </ div > } </ Composed > )
133+ const Composed = adopt ( { foo : 'helo' } as any )
134+ return shallow ( < Composed > { props => < div > foo</ div > } </ Composed > )
107135 } ) . toThrowError (
108136 'The render props object mapper just accept valid elements as value'
109137 )
0 commit comments