API
createMount(plugins) => (node: React.ReactElement, options? Object) => ContextReactWrapper
createMount(plugins) => (node: React.ReactElement, options? Object) => ContextReactWrapperArguments
plugins(Object): an object where the keys are names of your choice and the values areenzyme-contextMountPlugins.
Returns
A mount function: (node: React.ReactElement, options?: Object) => ContextReactWrapper: A function that takes the same arguments as mount but can also accept additional options (as specified by the provided plugins.)
Arguments
node(React.ReactElement): The node to renderoptions(Object[optional]): The same options that can be passed to enzyme's mount plus any options the plugins you've added handle.
Returns
A
ReactWrapperwith the following attributes:[keyof plugins]: EnzymePlugin['controller']: the returnedReactWrapperwill have a key that matches each key in thepluginsyou provide. The value will be whatevercontrollerthe plugin provides. For example, theenzyme-context-reduxplugin provides aStore; theenzyme-context-react-router-4plugin provides aHistory.
Example
test-utils/enzyme.ts
import { createMount } from 'enzyme-context';
import { reduxContext } from 'enzyme-context-redux';
import { routerContext } from 'enzyme-context-react-router-4';
import { createStore } from 'redux';
import reducer from './reducer'; // this is _your_ app's main reducer
export const mount = createMount({
store: reduxContext({
createStore: () => createStore(reducer),
}),
history: routerContext(),
});MyComponent.spec.tsx
createShallow(plugins) => (node: React.ReactElement, options? Object) => ContextShallowWrapper
createShallow(plugins) => (node: React.ReactElement, options? Object) => ContextShallowWrapperArguments
plugins(Object): an object where the keys are names of your choice and the values areenzyme-contextMountPlugins.
Returns
A shallow function: (node: React.ReactElement, options?: Object) => ContextShallowWrapper: A function that takes the same arguments as shallow but can also accept additional options (as specified by the provided plugins.)
Arguments
node(React.ReactElement): The node to renderoptions(Object[optional]): The same options that can be passed to enzyme's shallow plus any options the plugins you've added handle.
Returns
An
ShallowWrapperwith the following attributes:[keyof plugins]: EnzymePlugin['controller']: the returned object will have a key that matches each key in thepluginsyou provide. The value will be whatevercontrollerthe plugin provides. For example, theenzyme-context-reduxplugin provides aStore; theenzyme-context-react-router-4plugin provides aHistory.
Example
test-utils/enzyme.ts
MyComponent.spec.tsx
Last updated
Was this helpful?