All files / enzyme/src index.js

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                        98x                   105x                               6x 6x          
import cheerio from 'cheerio';
import ReactWrapper from './ReactWrapper';
import ShallowWrapper from './ShallowWrapper';
import { renderToStaticMarkup } from './react-compat';
 
/**
 * Mounts and renders a react component into the document and provides a testing wrapper around it.
 *
 * @param node
 * @returns {ReactWrapper}
 */
export function mount(node, options) {
  return new ReactWrapper(node, null, options);
}
 
/**
 * Shallow renders a react component and provides a testing wrapper around it.
 *
 * @param node
 * @returns {ShallowWrapper}
 */
export function shallow(node, options) {
  return new ShallowWrapper(node, null, options);
}
 
/**
 * Renders a react component into static HTML and provides a cheerio wrapper around it. This is
 * somewhat asymmetric with `mount` and `shallow`, which don't use any external libraries, but
 * Cheerio's API is pretty close to what we actually want and has a significant amount of utility
 * that would be recreating the wheel if we didn't use it.
 *
 * I think there are a lot of good use cases to use `render` instead of `shallow` or `mount`, and
 * thus I'd like to keep this API in here even though it's not really "ours".
 *
 * @param node
 * @returns {Cheerio}
 */
export function render(node) {
  const html = renderToStaticMarkup(node);
  return cheerio.load(html).root();
}
 
export { ShallowWrapper as ShallowWrapper };
export { ReactWrapper as ReactWrapper };