Skip to content

feat: add toJSON to render; cleanup shallow #35

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 5 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"react": ">=16.0.0",
"react-test-renderer": ">= 16.0.0"
},
"dependencies": {
"react-is": "^16.5.2"
},
"scripts": {
"test": "jest",
"flow-check": "flow check",
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/__snapshots__/render.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`toJSON 1`] = `"press me"`;
6 changes: 6 additions & 0 deletions src/__tests__/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ test('unmount', () => {
unmount();
expect(fn).toHaveBeenCalled();
});

test('toJSON', () => {
const { toJSON } = render(<Button>press me</Button>);

expect(toJSON()).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion src/debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import prettyFormat, { plugins } from 'pretty-format'; // eslint-disable-line import/no-extraneous-dependencies
import shallow from './shallow';
import { shallow } from '.';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a cyclic dependency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, yea, reverting


/**
* Log pretty-printed shallow test component instance
Expand Down
1 change: 1 addition & 0 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default function render(
...queryByAPI(instance),
update: renderer.update,
unmount: renderer.unmount,
toJSON: renderer.toJSON,
};
}
12 changes: 3 additions & 9 deletions src/shallow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import * as React from 'react';
import { isValidElementType } from 'react-is';
import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies

/**
Expand All @@ -10,15 +9,10 @@ export default function shallow(
instance: ReactTestInstance | React.Element<*>
) {
const renderer = new ShallowRenderer();
if (isValidElementType(instance)) {
// $FlowFixMe - instance is React.Element<*> in this branch
renderer.render(instance);
} else {
renderer.render(React.createElement(instance.type, instance.props));
}
const output = renderer.getRenderOutput();

renderer.render(React.createElement(instance.type, instance.props));

return {
output,
output: renderer.getRenderOutput(),
};
}