import * as React from 'react'; import { ReactShallowRenderer } from '../../src'; import { elementSymbol } from '../../src/constants'; import { compare } from '../helpers/compare'; describe('ReactShallowRenderer', () => { const ComponentWithFalsyChildren: React.FunctionComponent = () => (

{null}

{false}

); const ComponentWithMappedChildren: React.FunctionComponent = () => (
{[1, 2, 3].map(child => (

{child}

))} {[[
]]}
); describe('toJSON', () => { it('renders some simple HTML', () => { const element = (

I am a child!

I am text!
); const renderer = new ReactShallowRenderer(element); compare(renderer.toJSON(), { $$typeof: elementSymbol, type: 'div', key: null, ref: null, props: { children: [ { $$typeof: elementSymbol, type: 'p', key: null, ref: null, props: { children: ['I am a child!'], }, _owner: null, _store: {}, }, 'I am text!', ], }, _owner: null, _store: {}, }); }); it('renders a component with a falsy children', () => { const element = ; const renderer = new ReactShallowRenderer(element); compare(renderer.toJSON(), { $$typeof: elementSymbol, type: 'div', key: null, ref: null, props: { children: [ { $$typeof: elementSymbol, type: 'p', key: null, ref: null, props: { children: [null], }, _owner: null, _store: {}, }, { $$typeof: elementSymbol, type: 'p', key: null, ref: null, props: { children: [false], }, _owner: null, _store: {}, }, ], }, _owner: null, _store: {}, }); }); it('renders a component with mapped (nested) children', () => { const element = ; const renderer = new ReactShallowRenderer(element); compare(renderer.toJSON(), { $$typeof: elementSymbol, type: 'div', key: null, ref: null, props: { children: [ [ { $$typeof: elementSymbol, type: 'p', key: '1', ref: null, props: { children: [1], }, _owner: null, _store: {}, }, { $$typeof: elementSymbol, type: 'p', key: '2', ref: null, props: { children: [2], }, _owner: null, _store: {}, }, { $$typeof: elementSymbol, type: 'p', key: '3', ref: null, props: { children: [3], }, _owner: null, _store: {}, }, ], [ [ { $$typeof: elementSymbol, type: 'div', key: '1', ref: null, props: { children: [], }, _owner: null, _store: {}, }, ], ], ], }, _owner: null, _store: {}, }); }); }); });