Skip to content

test(ReactElementToJsxString): Add test when dealing with element inside prop object #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"babel-register": "6.26.0",
"conventional-changelog-cli": "2.0.5",
"doctoc": "1.3.1",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"eslint": "5.6.1",
"eslint-config-algolia": "13.2.3",
"eslint-config-prettier": "3.1.0",
Expand Down Expand Up @@ -82,5 +84,8 @@
"dependencies": {
"is-plain-object": "2.0.4",
"stringify-object": "3.2.2"
},
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>tests/setupTests.js"
}
}
28 changes: 27 additions & 1 deletion src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

/* eslint-disable react/no-string-refs */

import React, { Fragment } from 'react';
import React, { Fragment, Component } from 'react';
import { createRenderer } from 'react-test-renderer/shallow';
import { mount } from 'enzyme';
import reactElementToJSXString from './index';
import AnonymousStatelessComponent from './AnonymousStatelessComponent';

Expand Down Expand Up @@ -1087,4 +1088,29 @@ describe('reactElementToJSXString(ReactElement)', () => {
)
).toEqual(`<div render={<><div /><div /></>} />`);
});

it('should not cause recursive loop when prop object contains an element', () => {
const Test = () => <div>Test</div>;

const Container = ({ title: { component } }) => <div>{component}</div>;

class App extends Component {
render() {
const inside = <Container title={{ component: <Test /> }} />;

const insideString = reactElementToJSXString(inside);

return (
<div>
{insideString}

<div id="hello" />

<p>Start editing to see some magic happen :)</p>
</div>
);
}
}
expect(mount(<App />).find('#hello')).toHaveLength(1);
});
});
4 changes: 4 additions & 0 deletions tests/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
Loading