Skip to content

React warning logged when using renderProp #2030

@lo1tuma

Description

@lo1tuma

Current behavior

When a renderProp function renders a string or null I see the following react warning being logged at stdout:

Warning: Failed prop type: The prop `children` is marked as required in `SimpleSFCWrapper`, but its value is `null`.
    in SimpleSFCWrapper

Same for a string:

Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `SimpleSFCWrapper`, expected a single ReactElement.
   in SimpleSFCWrapper

Expected behavior

I wouldn’t expect to see such a warning since everything works just fine when using null or string values.

Your environment

I’ve created a minimal example to reproduce this issue:

  • run npm i react@16.8.3 enzyme@3.9.0 enzyme-adapter-react-16@1.10.0 react-dom@16.8.3
  • create a file test.js which the following content:
'use strict';

const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
const React = require('react');

Enzyme.configure({ adapter: new Adapter() });

const { shallow } = Enzyme;

function MyComponent() {
    return React.createElement('div', {},
        React.createElement(ComponentWithRenderProp, {}, function (value) {
            return value;
        })
    );
}

function ComponentWithRenderProp(props) {
    return props.children('foo');
}

const myComponent = shallow(React.createElement(MyComponent));

myComponent.find(ComponentWithRenderProp).renderProp('children')('bar');
  • run node test.js

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.9.0
react 16.8.3
react-dom 16.8.3
react-test-renderer 16.8.3
adapter (below) 1.10.0

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions