diff --git a/index-test.js b/index-test.js index 52cce9075..6c4766c4c 100644 --- a/index-test.js +++ b/index-test.js @@ -152,11 +152,27 @@ describe(`reactElementToJSXString(ReactElement)`, () => { }).toThrow('react-element-to-jsx-string: Expected a ReactElement'); }); - it('ignores object keys order (sortobject)', () => { + it(`ignores object keys order (sortobject)`, () => { expect( reactElementToJSXString(
) ).toEqual( reactElementToJSXString() ); }); + + it(`reactElementToJSXString(`, () => { + expect( + reactElementToJSXString() + ).toEqual( + reactElementToJSXString() + ); + }); + + it(`reactElementToJSXString(`, () => { + expect( + reactElementToJSXString() + ).toEqual( + reactElementToJSXString() + ); + }); }); diff --git a/index.js b/index.js index b923e4e4a..d8fbe290a 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,7 @@ function recurse({lvl, inline}) { function stringifyObject(obj) { // sortobject fails on some types, like regex - if (Object.keys(obj).length > 0) { + if (obj && Object.keys(obj).length > 0) { obj = sortobject(obj); }