Reading Class 19 - meron-401n14/seattle-javascript-401n14 GitHub Wiki

Shallow rendering API

Useful to constrain yourself to testing a component as a unit, and to ensure that your tests aren’t indirectly asserting on behavior of child components.

Shallow API does call React lifecycle methods such as componentDidMount and componentDidUpdate.

Shallow(node[, options]) =>

ShallowWrapper

Arguments

  1. Node (ReactElemnt) : the node to render
  2. Options (object, [optional]):
  • Options.context: (object, [optional]): context to be passed to the component
  • Options.diableLifecycleMethods: (Boolean [optional]): if set to true, componentDidMount is not called on the component, and componentDidUpdate is not called after setProps and setContext. Default to false.
  • Options.wrappingComponent: (component Type [optional]): A component that will render as a parent of the node. It can be used to provide context to the node, among other things. See the getWrappingComponent() docs for for an example. Note: wrappingComponent must render its children.
  • Options.wrappingComponentProps(object [optional]): initial props to pass to the wrappingComponent if it is specified.
  • Options.suspenseFallback: (Boolean [optional]) if set to true, when rendering Suspense enzyme will replace all the lazy components in children with fallback element prop. Otherwise it won’t handle fallback of lazy component. Default to true.