feat: add toJSON to render; cleanup shallow (#35)

* feat: add toJSON to render; cleanup shallow

* Remove empty dependencies entry

* revert shallow import

* add docs

* add TS typings
This commit is contained in:
Michał Pierzchała
2018-10-16 18:00:54 +02:00
committed by GitHub
parent 61f6895b32
commit 07d3be1c51
7 changed files with 19 additions and 13 deletions
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`toJSON 1`] = `"press me"`;
+6
View File
@@ -161,3 +161,9 @@ test('unmount', () => {
unmount();
expect(fn).toHaveBeenCalled();
});
test('toJSON', () => {
const { toJSON } = render(<Button>press me</Button>);
expect(toJSON()).toMatchSnapshot();
});
+1
View File
@@ -20,5 +20,6 @@ export default function render(
...queryByAPI(instance),
update: renderer.update,
unmount: renderer.unmount,
toJSON: renderer.toJSON,
};
}
+3 -9
View File
@@ -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
/**
@@ -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(),
};
}