mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Document test helpers
This commit is contained in:
parent
8f92ec2855
commit
cfbeb8672c
1 changed files with 14 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ import { BrowserRouter } from 'react-router';
|
|||
import { Provider } from 'react-redux';
|
||||
import configureStore from '../store';
|
||||
|
||||
// Provide all the context for components that connect to the Redux
|
||||
// store, i18n, router, etc.
|
||||
export const TestProvider = props => {
|
||||
const store = configureStore();
|
||||
return (
|
||||
|
|
@ -20,10 +22,22 @@ export const TestProvider = props => {
|
|||
);
|
||||
};
|
||||
|
||||
// Use Enzyme's shallow rendering to render the given component to a
|
||||
// JSON structure that can be used in snapshot tests. This doesn't
|
||||
// render the children within the given component, only a
|
||||
// representation of the child component and its props.
|
||||
//
|
||||
// Useful for snapshot testing components that contain shared
|
||||
// components. With deep rendering, if the child component changes
|
||||
// internally, the test for the given component would also fail. This
|
||||
// avoids the problem by not rendering the full tree but only the
|
||||
// relevant structure for the given component.
|
||||
export const renderShallow = component => {
|
||||
return toJson(shallow(component));
|
||||
};
|
||||
|
||||
// Fully render the given component to a JSON structure that can be
|
||||
// used in snapshot tests.
|
||||
export const renderDeep = component => {
|
||||
const comp = renderer.create(
|
||||
<TestProvider>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue