Skip to content
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

Don't process non-plain objects in props #25

Merged
merged 1 commit into from
Nov 1, 2016
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
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();
});