diff --git a/.eslintrc b/.eslintrc index d603c3b..9dd49d6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -108,16 +108,11 @@ rules: prefer-spread: 2 max-len: [2, 260] no-template-curly-in-string: 2 + generator-star-spacing: [2, both] + object-shorthand: [2, always] + arrow-parens: [2, as-needed] react/jsx-uses-react: 2 react/jsx-uses-vars: 2 - # disable builtin rules that are incompatible with Babel plugin ones - generator-star-spacing: 0 - object-shorthand: 0 - arrow-parens: 0 - - babel/generator-star-spacing: [2, both] - babel/object-shorthand: [2, always] - babel/arrow-parens: [2, as-needed] babel/no-await-in-loop: 2 diff --git a/.gitignore b/.gitignore index a388591..cab03c3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules coverage build /serializer.js +npm-debug.log diff --git a/src/render.js b/src/render.js index 8123d52..6c169a9 100644 --- a/src/render.js +++ b/src/render.js @@ -3,7 +3,9 @@ import compact from 'lodash.compact'; const renderChildToJson = child => { if(!child) return null; - if(child.type === 'tag') { + if(child.type === 'root') { + return renderChildToJson(child.children[0]); + } else if(child.type === 'tag') { return { type: child.name, props: child.attribs, @@ -15,4 +17,4 @@ const renderChildToJson = child => { } }; -export default wrapper => renderChildToJson(wrapper.children()[0]); +export default wrapper => renderChildToJson(wrapper[0]); diff --git a/tests/core/__snapshots__/render.test.js.snap b/tests/core/__snapshots__/render.test.js.snap index 5d53b4e..b97d1d4 100644 --- a/tests/core/__snapshots__/render.test.js.snap +++ b/tests/core/__snapshots__/render.test.js.snap @@ -32,4 +32,15 @@ exports[`test converts basic pure render 1`] = ` `; +exports[`test renders the whole list 1`] = ` + +`; + exports[`test handles a component which returns null 1`] = `null`; diff --git a/tests/core/fixtures/pure-function.js b/tests/core/fixtures/pure-function.js index 5fa39f6..6c62665 100644 --- a/tests/core/fixtures/pure-function.js +++ b/tests/core/fixtures/pure-function.js @@ -16,3 +16,14 @@ export function BasicWithUndefined(props) { ); } + +export function BasicWithAList() { + return ( +
+ +
+ ); +} diff --git a/tests/core/render.test.js b/tests/core/render.test.js index af60c63..eb61fd9 100644 --- a/tests/core/render.test.js +++ b/tests/core/render.test.js @@ -3,7 +3,7 @@ import React from 'react'; import { render } from 'enzyme'; import { renderToJson } from '../../src'; -import { BasicPure } from './fixtures/pure-function'; +import { BasicPure, BasicWithAList } from './fixtures/pure-function'; import { BasicClass, ClassWithNull } from './fixtures/class'; it('converts basic pure render', () => { @@ -22,6 +22,11 @@ it('converts basic class render', () => { expect(renderToJson(rendered)).toMatchSnapshot(); }); +it('renders the whole list', () => { + const wrapper = render(); + expect(renderToJson(wrapper.find('ul'))).toMatchSnapshot(); +}); + it('handles a component which returns null', () => { const rendered = render(