1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import * as ReactDOM from 'react-dom';
|
5 | import * as PropTypes from 'prop-types';
|
6 | import { mount as enzymeMount } from 'enzyme';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | class Mode extends React.Component {
|
17 | render() {
|
18 |
|
19 | const _this$props = this.props,
|
20 | {
|
21 | __element,
|
22 | __strict
|
23 | } = _this$props,
|
24 | other = _objectWithoutPropertiesLoose(_this$props, ["__element", "__strict"]);
|
25 |
|
26 | const Component = __strict ? React.StrictMode : React.Fragment;
|
27 | return React.createElement(Component, null, React.cloneElement(__element, other));
|
28 | }
|
29 |
|
30 | }
|
31 |
|
32 | process.env.NODE_ENV !== "production" ? Mode.propTypes = {
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 | __element: PropTypes.element.isRequired,
|
39 | __strict: PropTypes.bool.isRequired
|
40 | } : void 0;
|
41 | let warnedOnce = false;
|
42 |
|
43 | export default function createMount(options = {}) {
|
44 | if (!warnedOnce) {
|
45 | warnedOnce = true;
|
46 | console.warn(['Material-UI: the test utils are deprecated, they are no longer present in v5.', 'The helpers were designed to work with enzyme.', 'However, the tests of the core components were moved to react-testing-library.'].join('\n'));
|
47 | }
|
48 |
|
49 | const {
|
50 | mount = enzymeMount,
|
51 | strict: globalStrict
|
52 | } = options,
|
53 | globalEnzymeOptions = _objectWithoutPropertiesLoose(options, ["mount", "strict"]);
|
54 |
|
55 | const attachTo = document.createElement('div');
|
56 | attachTo.className = 'app';
|
57 | attachTo.setAttribute('id', 'app');
|
58 | document.body.insertBefore(attachTo, document.body.firstChild);
|
59 |
|
60 | const mountWithContext = function mountWithContext(node, localOptions = {}) {
|
61 | const {
|
62 | disableUnnmount = false,
|
63 | strict = globalStrict
|
64 | } = localOptions,
|
65 | localEnzymeOptions = _objectWithoutPropertiesLoose(localOptions, ["disableUnnmount", "strict"]);
|
66 |
|
67 | if (!disableUnnmount) {
|
68 | ReactDOM.unmountComponentAtNode(attachTo);
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 | return mount(strict == null ? node : React.createElement(Mode, {
|
74 | __element: node,
|
75 | __strict: Boolean(strict)
|
76 | }), _extends({
|
77 | attachTo
|
78 | }, globalEnzymeOptions, localEnzymeOptions));
|
79 | };
|
80 |
|
81 | mountWithContext.attachTo = attachTo;
|
82 |
|
83 | mountWithContext.cleanUp = () => {
|
84 | ReactDOM.unmountComponentAtNode(attachTo);
|
85 | attachTo.parentElement.removeChild(attachTo);
|
86 | };
|
87 |
|
88 | return mountWithContext;
|
89 | } |
\ | No newline at end of file |