Skip to content

Commit

Permalink
feat(sortObject): Add a test for issue 344 (#357)
Browse files Browse the repository at this point in the history
fixes #334
  • Loading branch information
skvale authored and vvo committed Jul 19, 2019
1 parent 8c6d6af commit 5fe7604
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/formatter/sortObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ export default function sortObject(value: any): any {
if (key === '_owner') {
return result;
}
// eslint-disable-next-line no-param-reassign
result[key] = sortObject(value[key]);
if (key === 'current') {
// eslint-disable-next-line no-param-reassign
result[key] = '[Circular]';
} else {
// eslint-disable-next-line no-param-reassign
result[key] = sortObject(value[key]);
}
return result;
}, {});
}
23 changes: 23 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,4 +1126,27 @@ describe('reactElementToJSXString(ReactElement)', () => {
}
expect(mount(<App />).find('#hello')).toHaveLength(1);
});

it('should not cause recursive loop when an element contains a ref', () => {
expect.assertions(1);
class App extends Component {
constructor(props) {
super(props);
this.inputRef = React.createRef();
}
componentDidMount() {
expect(reactElementToJSXString(<input ref={this.inputRef} />)).toEqual(
`<input
ref={{
current: '[Circular]'
}}
/>`
);
}
render() {
return <input ref={this.inputRef} />;
}
}
mount(<App />);
});
});

0 comments on commit 5fe7604

Please sign in to comment.