File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
packages/react-form-renderer/src Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ const renderChildren = (children, props) => {
2323 * Only permit one child element
2424 */
2525 if ( children . length !== 1 ) {
26- throw new Error ( 'FormRenderer expect only one child element!' ) ;
26+ throw new Error ( 'FormRenderer expects only one child element!' ) ;
2727 }
2828
2929 childElement = children [ 0 ] ;
Original file line number Diff line number Diff line change @@ -384,5 +384,42 @@ describe('<FormRenderer />', () => {
384384
385385 expect ( submitSpy ) . toHaveBeenCalledWith ( { foo : 'bar' } , expect . any ( Object ) , expect . any ( Function ) ) ;
386386 } ) ;
387+
388+ it ( 'should render null as a child' , ( ) => {
389+ expect ( ( ) => {
390+ render (
391+ < FormRenderer initialValues = { { foo : 'bar' } } componentMapper = { componentMapper } schema = { schema } >
392+ { null }
393+ </ FormRenderer >
394+ ) ;
395+ } ) . not . toThrow ( ) ;
396+ } ) ;
397+
398+ it ( 'should throw an error if more than one child was passed' , ( ) => {
399+ expect ( ( ) => {
400+ render (
401+ < FormRenderer initialValues = { { foo : 'bar' } } componentMapper = { componentMapper } schema = { schema } >
402+ < div />
403+ < div />
404+ </ FormRenderer >
405+ ) ;
406+ } ) . toThrow ( 'FormRenderer expects only one child element!' ) ;
407+ } ) ;
408+
409+ it ( 'should not override schema or formFields prop if explicitely given to child' , ( ) => {
410+ const ChildSpy = ( { schema, formFields } ) => (
411+ < div >
412+ < div > { schema } </ div >
413+ < div > { formFields } </ div >
414+ </ div >
415+ ) ;
416+ render (
417+ < FormRenderer initialValues = { { foo : 'bar' } } componentMapper = { componentMapper } schema = { schema } >
418+ < ChildSpy schema = "schema-prop" formFields = "form-fields-prop" />
419+ </ FormRenderer >
420+ ) ;
421+ expect ( screen . getByText ( 'schema-prop' ) ) . toBeInTheDocument ( ) ;
422+ expect ( screen . getByText ( 'form-fields-prop' ) ) . toBeInTheDocument ( ) ;
423+ } ) ;
387424 } ) ;
388425} ) ;
You can’t perform that action at this time.
0 commit comments