UG_ UG_ - 8 months ago 122
React JSX Question

React Snapshot testing with jest - Failed prop type: Invalid prop `children` of type `string` supplied

I am trying to test a pure react component.


import React, {Component} from 'react';

class App extends Component {
constructor (props){

render() {
return (
<div className="container-wrapper">

App.propTypes = {
init : React.PropTypes.func,
children : React.PropTypes.element,
export default App;

Jest Snapshot Test

import React from 'react';
import App from 'app/main/components/App';
import renderer from 'react-test-renderer';

const blank = jest.fn();
describe('App', () => {
it('Renders App', () => {
const component = renderer.create(<App init={blank}> </App>);
const tree = component.toJSON();

When I execute the test I get below error.

console.error node_modules/fbjs/lib/warning.js:36
Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `App`, expected a single ReactElement.
in App

I can understand that is says Props.children is invalid. How can I mock props.children? Or is there some other way test such components


You can simply pass a child to your component:

it('Renders App', () => {
    const component = renderer.create(
        <App init={blank}>
            Hello App.
    const tree = component.toJSON();