mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
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:
committed by
GitHub
parent
61f6895b32
commit
07d3be1c51
@@ -0,0 +1,3 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`toJSON 1`] = `"press me"`;
|
||||
@@ -161,3 +161,9 @@ test('unmount', () => {
|
||||
unmount();
|
||||
expect(fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('toJSON', () => {
|
||||
const { toJSON } = render(<Button>press me</Button>);
|
||||
|
||||
expect(toJSON()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -20,5 +20,6 @@ export default function render(
|
||||
...queryByAPI(instance),
|
||||
update: renderer.update,
|
||||
unmount: renderer.unmount,
|
||||
toJSON: renderer.toJSON,
|
||||
};
|
||||
}
|
||||
|
||||
+3
-9
@@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user