Skip to content

Commit

Permalink
Fix script tags returning null on render
Browse files Browse the repository at this point in the history
Fixes #133
  • Loading branch information
Adrien Weissberg committed Sep 19, 2019
1 parent a8f9fcf commit ae563f4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const renderChildToJson = (child, options) => {
return null;
}

if (child.type === 'tag') {
if (['tag', 'script'].includes(child.type)) {
return applyMap(
{
node: child,
Expand Down
12 changes: 12 additions & 0 deletions tests/__snapshots__/render.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ Array [
]
`;

exports[`renders an external script 1`] = `
<script
src="http://www.example.com/foo.js"
/>
`;

exports[`renders an inline script 1`] = `
<script>
console.log('hi there');
</script>
`;

exports[`renders multiple elements as a result of find 1`] = `
Array [
<li>
Expand Down
14 changes: 13 additions & 1 deletion tests/fixtures/pure-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,21 @@ export const ComponentWithMemo = () => (

export const ComponentWithChildren = ({children}) => <span>{children}</span>;

export const WithDefaultProps = ({value, falsyValue}) => <div>{value},{falsyValue}</div>;
export const WithDefaultProps = ({value, falsyValue}) => (
<div>
{value},{falsyValue}
</div>
);

WithDefaultProps.defaultProps = {
value: 'hi there',
falsyValue: false,
};

export const InlineScript = () => (
<script dangerouslySetInnerHTML={{__html: `console.log('hi there');`}} />
);

export const ExternalScript = () => (
<script src={'http://www.example.com/foo.js'} />
);
14 changes: 14 additions & 0 deletions tests/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ArrayRender,
FragmentAsChild,
FragmentAsRoot,
InlineScript,
ExternalScript,
} from './fixtures/pure-function';
import {
BasicClass,
Expand Down Expand Up @@ -161,3 +163,15 @@ it('renders a component that has a fragment root', () => {

expect(renderToJson(wrapper)).toMatchSnapshot();
});

it('renders an inline script', () => {
const wrapper = render(<InlineScript />);

expect(renderToJson(wrapper)).toMatchSnapshot();
});

it('renders an external script', () => {
const wrapper = render(<ExternalScript />);

expect(renderToJson(wrapper)).toMatchSnapshot();
});

0 comments on commit ae563f4

Please sign in to comment.