import React from 'react'; import renderer from 'react-test-renderer'; import { smartRender } from './'; type PropType = { title?: string }; const Component = (props: PropType = {}) =>
; class ClassComponent extends React.Component { render() { return
; } } describe('smartRender', () => { it('is renders basic elements', () => { expect(renderer.create(<>{smartRender('hello')}).toJSON()).toMatchInlineSnapshot(`"hello"`); expect(renderer.create(<>{smartRender(123)}).toJSON()).toMatchInlineSnapshot(`"123"`); expect(renderer.create(<>{smartRender(true)}).toJSON()).toMatchInlineSnapshot(`null`); expect(renderer.create(<>{smartRender(false)}).toJSON()).toMatchInlineSnapshot(`null`); expect(renderer.create(<>{smartRender(null)}).toJSON()).toMatchInlineSnapshot(`null`); }); it('is renders basic elements as fallback', () => { expect(renderer.create(<>{smartRender(undefined, {}, 'hello')}).toJSON()).toMatchInlineSnapshot(`"hello"`); expect(renderer.create(<>{smartRender(undefined, {}, 123)}).toJSON()).toMatchInlineSnapshot(`"123"`); expect(renderer.create(<>{smartRender(undefined, {}, true)}).toJSON()).toMatchInlineSnapshot(`null`); expect(renderer.create(<>{smartRender(undefined, {}, false)}).toJSON()).toMatchInlineSnapshot(`null`); expect(renderer.create(<>{smartRender(undefined, {}, null)}).toJSON()).toMatchInlineSnapshot(`null`); }); it('is renders basic elements with props', () => { expect(renderer.create(<>{smartRender('hello', { prop: 'prop' })}).toJSON()).toMatchInlineSnapshot(`"hello"`); expect(renderer.create(<>{smartRender(123, { prop: 'prop' })}).toJSON()).toMatchInlineSnapshot(`"123"`); expect(renderer.create(<>{smartRender(undefined, { prop: 'prop' }, 'h')}).toJSON()).toMatchInlineSnapshot(`"h"`); expect(renderer.create(<>{smartRender(undefined, { prop: 'prop' }, 1)}).toJSON()).toMatchInlineSnapshot(`"1"`); }); it('is renders React elements', () => { expect(renderer.create(<>{smartRender()}).toJSON()).toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender(Component)}).toJSON()).toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender()}).toJSON()).toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender(ClassComponent)}).toJSON()).toMatchInlineSnapshot(`
`); }); it('is renders React elements with props', () => { expect( renderer .create( <> {smartRender(, { title: 'h' })} , ) .toJSON(), ).toMatchInlineSnapshot(`
`); expect( renderer .create( <> {smartRender(, { title: 'h' })} , ) .toJSON(), ).toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender()}).toJSON()).toMatchInlineSnapshot(`
`); expect( renderer .create( <> {smartRender(Component, { title: 'h' })} , ) .toJSON(), ).toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender()}).toJSON()).toMatchInlineSnapshot(`
`); expect( renderer .create( <> {smartRender(ClassComponent, { title: 'h' })} , ) .toJSON(), ).toMatchInlineSnapshot(`
`); }); it('is renders fallback elements', () => { expect(renderer.create(<>{smartRender(undefined, {}, )}).toJSON()).toMatchInlineSnapshot( `
`, ); expect(renderer.create(<>{smartRender(undefined, {}, Component)}).toJSON()).toMatchInlineSnapshot( `
`, ); }); it('is renders fallback elements with props', () => { expect(renderer.create(<>{smartRender(undefined, {}, )}).toJSON()) .toMatchInlineSnapshot(`
`); expect(renderer.create(<>{smartRender(undefined, { title: 'h' }, Component)}).toJSON()) .toMatchInlineSnapshot(`
`); }); });