Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React warning logged when using renderProp #2030

Closed
2 of 13 tasks
lo1tuma opened this issue Mar 4, 2019 · 2 comments
Closed
2 of 13 tasks

React warning logged when using renderProp #2030

lo1tuma opened this issue Mar 4, 2019 · 2 comments

Comments

@lo1tuma
Copy link

lo1tuma commented Mar 4, 2019

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 ( )
@ljharb ljharb self-assigned this Mar 5, 2019
@ljharb ljharb closed this as completed in a00ed0b Mar 5, 2019
ljharb added a commit that referenced this issue Mar 9, 2019
 - [fix] allow `node`, not just `element` (#2030)
 - [meta] add "directory" field to package.json
 - [deps] update `prop-types`
 - [dev deps] update `eslint`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`
@lo1tuma
Copy link
Author

lo1tuma commented Mar 18, 2019

I’ve just noticed this has been only fixed partially.
With enzyme-adapter-react-16@1.11.2 I still get the following warning when returning null from a renderProp.

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

@ljharb
Copy link
Member

ljharb commented Mar 18, 2019

@lo1tuma please file another issue; making a wrapper around null seems strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants