UNPKG

enzyme

Version:

JavaScript Testing utilities for React

65 lines (52 loc) 1.97 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReactWrapper = exports.ShallowWrapper = undefined; exports.mount = mount; exports.shallow = shallow; exports.render = render; var _cheerio = require('cheerio'); var _cheerio2 = _interopRequireDefault(_cheerio); var _ReactWrapper = require('./ReactWrapper'); var _ReactWrapper2 = _interopRequireDefault(_ReactWrapper); var _ShallowWrapper = require('./ShallowWrapper'); var _ShallowWrapper2 = _interopRequireDefault(_ShallowWrapper); var _reactCompat = require('./react-compat'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } /** * Mounts and renders a react component into the document and provides a testing wrapper around it. * * @param node * @returns {ReactWrapper} */ function mount(node, options) { return new _ReactWrapper2['default'](node, null, options); } /** * Shallow renders a react component and provides a testing wrapper around it. * * @param node * @returns {ShallowWrapper} */ function shallow(node, options) { return new _ShallowWrapper2['default'](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} */ function render(node) { var html = (0, _reactCompat.renderToStaticMarkup)(node); return _cheerio2.default.load(html).root(); } exports.ShallowWrapper = _ShallowWrapper2['default']; exports.ReactWrapper = _ReactWrapper2['default'];