Skip to content

Commit

Permalink
fix: Don't process non-plain objects in props (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevoland authored and adriantoine committed Nov 1, 2016
1 parent bb6239c commit 3d04485
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"license": "MIT",
"dependencies": {
"lodash.compact": "^3.0.1",
"lodash.isplainobject": "^4.0.6",
"lodash.omit": "^4.5.0",
"object-values": "^1.0.0",
"object.entries": "^1.0.3"
Expand Down
3 changes: 2 additions & 1 deletion src/shallow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import compact from 'lodash.compact';
import isPlainObject from 'lodash.isplainobject';
import omit from 'lodash.omit';
import entries from 'object.entries';
import {propsOfNode} from 'enzyme/build/Utils';
Expand All @@ -18,7 +19,7 @@ function nodeToJson(node) {
return node.map(nodeToJson);
}

if (typeof node === 'object') {
if (isPlainObject(node)) {
return entries(node).reduce((obj, [key, val]) => {
obj[key] = nodeToJson(val);
return obj;
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/shallow.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ exports[`test handles elements in props 1`] = `
</BasicPure>
} />
`;

exports[`test ignores non-plain objects 1`] = `
<BasicPure
instance={
TestConstructor {
"_test": true,
}
} />
`;
12 changes: 12 additions & 0 deletions test/shallow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ it('handles elements in prop objects', () => {

expect(shallowToJson(shallowed)).toMatchSnapshot();
});

it('ignores non-plain objects', () => {
function TestConstructor() {
this._test = true;
}

const shallowed = shallow(
<WrapperComponent instance={new TestConstructor()} />
);

expect(shallowToJson(shallowed)).toMatchSnapshot();
});

0 comments on commit 3d04485

Please sign in to comment.