cypress 13.11.0 → 13.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/angular/angular/dist/index.d.ts +1 -1
- package/angular/angular/dist/index.js +239 -239
- package/angular/angular/package.json +1 -1
- package/angular/dist/index.d.ts +1 -1
- package/angular/dist/index.js +239 -239
- package/angular/package.json +1 -1
- package/lib/cli.js +0 -1
- package/lib/exec/xvfb.js +0 -1
- package/lib/logger.js +0 -3
- package/mount-utils/dist/index.d.ts +1 -1
- package/mount-utils/mount-utils/dist/index.d.ts +1 -1
- package/mount-utils/mount-utils/package.json +1 -1
- package/mount-utils/package.json +1 -1
- package/package.json +3 -3
- package/react/dist/cypress-react.cjs.js +237 -237
- package/react/dist/cypress-react.esm-bundler.js +237 -237
- package/react/dist/index.d.ts +1 -1
- package/react/package.json +3 -3
- package/react/react/dist/cypress-react.cjs.js +237 -237
- package/react/react/dist/cypress-react.esm-bundler.js +237 -237
- package/react/react/dist/index.d.ts +1 -1
- package/react/react/package.json +3 -3
- package/react18/dist/cypress-react.cjs.js +222 -222
- package/react18/dist/cypress-react.esm-bundler.js +222 -222
- package/react18/dist/index.d.ts +1 -1
- package/react18/package.json +1 -1
- package/react18/react18/dist/cypress-react.cjs.js +222 -222
- package/react18/react18/dist/cypress-react.esm-bundler.js +222 -222
- package/react18/react18/dist/index.d.ts +1 -1
- package/react18/react18/package.json +1 -1
- package/svelte/dist/cypress-svelte.cjs.js +61 -61
- package/svelte/dist/cypress-svelte.esm-bundler.js +61 -61
- package/svelte/dist/index.d.ts +2 -2
- package/svelte/package.json +1 -1
- package/svelte/svelte/dist/cypress-svelte.cjs.js +61 -61
- package/svelte/svelte/dist/cypress-svelte.esm-bundler.js +61 -61
- package/svelte/svelte/dist/index.d.ts +2 -2
- package/svelte/svelte/package.json +1 -1
- package/vue/dist/cypress-vue.cjs.js +128 -128
- package/vue/dist/cypress-vue.esm-bundler.js +128 -128
- package/vue/dist/index.d.ts +5 -5
- package/vue/package.json +5 -5
- package/vue/vue/dist/cypress-vue.cjs.js +128 -128
- package/vue/vue/dist/cypress-vue.esm-bundler.js +128 -128
- package/vue/vue/dist/index.d.ts +5 -5
- package/vue/vue/package.json +5 -5
- package/vue2/dist/cypress-vue2.cjs.js +211 -211
- package/vue2/dist/cypress-vue2.esm-bundler.js +211 -211
- package/vue2/dist/index.d.ts +11 -11
- package/vue2/package.json +1 -1
- package/vue2/vue2/dist/cypress-vue2.cjs.js +211 -211
- package/vue2/vue2/dist/cypress-vue2.esm-bundler.js +211 -211
- package/vue2/vue2/dist/index.d.ts +11 -11
- package/vue2/vue2/package.json +1 -1
@@ -29,41 +29,41 @@ function _interopNamespaceDefault(e) {
|
|
29
29
|
|
30
30
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
31
31
|
|
32
|
-
/**
|
33
|
-
* Gets the display name of the component when possible.
|
34
|
-
* @param type {JSX} The type object returned from creating the react element.
|
35
|
-
* @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
|
36
|
-
* @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
|
37
|
-
*/
|
38
|
-
function getDisplayName(node, fallbackName = 'Unknown') {
|
39
|
-
const type = node === null || node === void 0 ? void 0 : node.type;
|
40
|
-
if (!type) {
|
41
|
-
return fallbackName;
|
42
|
-
}
|
43
|
-
let displayName = null;
|
44
|
-
// The displayName property is not guaranteed to be a string.
|
45
|
-
// It's only safe to use for our purposes if it's a string.
|
46
|
-
// github.com/facebook/react-devtools/issues/803
|
47
|
-
if (typeof type.displayName === 'string') {
|
48
|
-
displayName = type.displayName;
|
49
|
-
}
|
50
|
-
if (!displayName) {
|
51
|
-
displayName = type.name || fallbackName;
|
52
|
-
}
|
53
|
-
// Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
|
54
|
-
// We need displayName with module name for error reports but it clutters the DevTools.
|
55
|
-
const match = displayName.match(/^(.*) \[from (.*)\]$/);
|
56
|
-
if (match) {
|
57
|
-
const componentName = match[1];
|
58
|
-
const moduleName = match[2];
|
59
|
-
if (componentName && moduleName) {
|
60
|
-
if (moduleName === componentName ||
|
61
|
-
moduleName.startsWith(`${componentName}.`)) {
|
62
|
-
displayName = componentName;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
return displayName;
|
32
|
+
/**
|
33
|
+
* Gets the display name of the component when possible.
|
34
|
+
* @param type {JSX} The type object returned from creating the react element.
|
35
|
+
* @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
|
36
|
+
* @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
|
37
|
+
*/
|
38
|
+
function getDisplayName(node, fallbackName = 'Unknown') {
|
39
|
+
const type = node === null || node === void 0 ? void 0 : node.type;
|
40
|
+
if (!type) {
|
41
|
+
return fallbackName;
|
42
|
+
}
|
43
|
+
let displayName = null;
|
44
|
+
// The displayName property is not guaranteed to be a string.
|
45
|
+
// It's only safe to use for our purposes if it's a string.
|
46
|
+
// github.com/facebook/react-devtools/issues/803
|
47
|
+
if (typeof type.displayName === 'string') {
|
48
|
+
displayName = type.displayName;
|
49
|
+
}
|
50
|
+
if (!displayName) {
|
51
|
+
displayName = type.name || fallbackName;
|
52
|
+
}
|
53
|
+
// Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
|
54
|
+
// We need displayName with module name for error reports but it clutters the DevTools.
|
55
|
+
const match = displayName.match(/^(.*) \[from (.*)\]$/);
|
56
|
+
if (match) {
|
57
|
+
const componentName = match[1];
|
58
|
+
const moduleName = match[2];
|
59
|
+
if (componentName && moduleName) {
|
60
|
+
if (moduleName === componentName ||
|
61
|
+
moduleName.startsWith(`${componentName}.`)) {
|
62
|
+
displayName = componentName;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return displayName;
|
67
67
|
}
|
68
68
|
|
69
69
|
const ROOT_SELECTOR = '[data-cy-root]';
|
@@ -115,141 +115,141 @@ function setupHooks(optionalCallback) {
|
|
115
115
|
});
|
116
116
|
}
|
117
117
|
|
118
|
-
let mountCleanup;
|
119
|
-
/**
|
120
|
-
* Create an `mount` function. Performs all the non-React-version specific
|
121
|
-
* behavior related to mounting. The React-version-specific code
|
122
|
-
* is injected. This helps us to maintain a consistent public API
|
123
|
-
* and handle breaking changes in React's rendering API.
|
124
|
-
*
|
125
|
-
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
126
|
-
* or people writing adapters for third-party, custom adapters.
|
127
|
-
*/
|
128
|
-
const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
|
129
|
-
if (!internalMountOptions) {
|
130
|
-
throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
|
131
|
-
}
|
132
|
-
// @ts-expect-error - this is removed but we want to check if a user is passing it, and error if they are.
|
133
|
-
if (options.alias) {
|
134
|
-
// @ts-expect-error
|
135
|
-
Cypress.utils.throwErrByPath('mount.alias', options.alias);
|
136
|
-
}
|
137
|
-
checkForRemovedStyleOptions(options);
|
138
|
-
mountCleanup = internalMountOptions.cleanup;
|
139
|
-
return cy
|
140
|
-
.then(() => {
|
141
|
-
var _a, _b, _c;
|
142
|
-
const reactDomToUse = internalMountOptions.reactDom;
|
143
|
-
const el = getContainerEl();
|
144
|
-
if (!el) {
|
145
|
-
throw new Error([
|
146
|
-
`[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
|
147
|
-
].join(' '));
|
148
|
-
}
|
149
|
-
const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
|
150
|
-
// @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
|
151
|
-
(((_c = (_b = (_a = Cypress === null || Cypress === void 0 ? void 0 : Cypress.mocha) === null || _a === void 0 ? void 0 : _a.getRunner()) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.title) || '') + Math.random();
|
152
|
-
const props = {
|
153
|
-
key,
|
154
|
-
};
|
155
|
-
const reactComponent = React__namespace.createElement(options.strict ? React__namespace.StrictMode : React__namespace.Fragment, props, jsx);
|
156
|
-
// since we always surround the component with a fragment
|
157
|
-
// let's get back the original component
|
158
|
-
const userComponent = reactComponent.props.children;
|
159
|
-
internalMountOptions.render(reactComponent, el, reactDomToUse);
|
160
|
-
return (cy.wrap(userComponent, { log: false })
|
161
|
-
.then(() => {
|
162
|
-
return cy.wrap({
|
163
|
-
component: userComponent,
|
164
|
-
rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
|
165
|
-
unmount: () => {
|
166
|
-
// @ts-expect-error - undocumented API
|
167
|
-
Cypress.utils.throwErrByPath('mount.unmount');
|
168
|
-
},
|
169
|
-
}, { log: false });
|
170
|
-
})
|
171
|
-
// by waiting, we delaying test execution for the next tick of event loop
|
172
|
-
// and letting hooks and component lifecycle methods to execute mount
|
173
|
-
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
|
174
|
-
.wait(0, { log: false })
|
175
|
-
.then(() => {
|
176
|
-
if (options.log !== false) {
|
177
|
-
// Get the display name property via the component constructor
|
178
|
-
// @ts-ignore FIXME
|
179
|
-
const componentName = getDisplayName(jsx);
|
180
|
-
const jsxComponentName = `<${componentName} ... />`;
|
181
|
-
Cypress.log({
|
182
|
-
name: type,
|
183
|
-
type: 'parent',
|
184
|
-
message: [jsxComponentName],
|
185
|
-
// @ts-ignore
|
186
|
-
$el: el.children.item(0),
|
187
|
-
consoleProps: () => {
|
188
|
-
return {
|
189
|
-
// @ts-ignore protect the use of jsx functional components use ReactNode
|
190
|
-
props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
|
191
|
-
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
|
192
|
-
home: 'https://github.com/cypress-io/cypress',
|
193
|
-
};
|
194
|
-
},
|
195
|
-
});
|
196
|
-
}
|
197
|
-
}));
|
198
|
-
// Bluebird types are terrible. I don't think the return type can be carried without this cast
|
199
|
-
});
|
200
|
-
};
|
201
|
-
/**
|
202
|
-
* Create an `unmount` function. Performs all the non-React-version specific
|
203
|
-
* behavior related to unmounting.
|
204
|
-
*
|
205
|
-
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
206
|
-
* or people writing adapters for third-party, custom adapters.
|
207
|
-
*
|
208
|
-
* @param {UnmountArgs} options used during unmounting
|
209
|
-
*/
|
210
|
-
const makeUnmountFn = (options) => {
|
211
|
-
return cy.then(() => {
|
212
|
-
var _a;
|
213
|
-
const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
214
|
-
if (wasUnmounted && options.log) {
|
215
|
-
Cypress.log({
|
216
|
-
name: 'unmount',
|
217
|
-
type: 'parent',
|
218
|
-
message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
|
219
|
-
consoleProps: () => {
|
220
|
-
return {
|
221
|
-
description: 'Unmounts React component',
|
222
|
-
parent: getContainerEl().parentNode,
|
223
|
-
home: 'https://github.com/cypress-io/cypress',
|
224
|
-
};
|
225
|
-
},
|
226
|
-
});
|
227
|
-
}
|
228
|
-
});
|
229
|
-
};
|
230
|
-
// Cleanup before each run
|
231
|
-
// NOTE: we cannot use unmount here because
|
232
|
-
// we are not in the context of a test
|
233
|
-
const preMountCleanup = () => {
|
234
|
-
mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
235
|
-
};
|
236
|
-
const _mount = (jsx, options = {}) => makeMountFn('mount', jsx, options);
|
237
|
-
const createMount = (defaultOptions) => {
|
238
|
-
return (element, options) => {
|
239
|
-
return _mount(element, Object.assign(Object.assign({}, defaultOptions), options));
|
240
|
-
};
|
241
|
-
};
|
242
|
-
// Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
|
243
|
-
// by creating an explicit function/import that the user can register in their 'component.js' support file,
|
244
|
-
// such as:
|
245
|
-
// import 'cypress/<my-framework>/support'
|
246
|
-
// or
|
247
|
-
// import { registerCT } from 'cypress/<my-framework>'
|
248
|
-
// registerCT()
|
249
|
-
// Note: This would be a breaking change
|
250
|
-
// it is required to unmount component in beforeEach hook in order to provide a clean state inside test
|
251
|
-
// because `mount` can be called after some preparation that can side effect unmount
|
252
|
-
// @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
|
118
|
+
let mountCleanup;
|
119
|
+
/**
|
120
|
+
* Create an `mount` function. Performs all the non-React-version specific
|
121
|
+
* behavior related to mounting. The React-version-specific code
|
122
|
+
* is injected. This helps us to maintain a consistent public API
|
123
|
+
* and handle breaking changes in React's rendering API.
|
124
|
+
*
|
125
|
+
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
126
|
+
* or people writing adapters for third-party, custom adapters.
|
127
|
+
*/
|
128
|
+
const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
|
129
|
+
if (!internalMountOptions) {
|
130
|
+
throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
|
131
|
+
}
|
132
|
+
// @ts-expect-error - this is removed but we want to check if a user is passing it, and error if they are.
|
133
|
+
if (options.alias) {
|
134
|
+
// @ts-expect-error
|
135
|
+
Cypress.utils.throwErrByPath('mount.alias', options.alias);
|
136
|
+
}
|
137
|
+
checkForRemovedStyleOptions(options);
|
138
|
+
mountCleanup = internalMountOptions.cleanup;
|
139
|
+
return cy
|
140
|
+
.then(() => {
|
141
|
+
var _a, _b, _c;
|
142
|
+
const reactDomToUse = internalMountOptions.reactDom;
|
143
|
+
const el = getContainerEl();
|
144
|
+
if (!el) {
|
145
|
+
throw new Error([
|
146
|
+
`[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
|
147
|
+
].join(' '));
|
148
|
+
}
|
149
|
+
const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
|
150
|
+
// @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
|
151
|
+
(((_c = (_b = (_a = Cypress === null || Cypress === void 0 ? void 0 : Cypress.mocha) === null || _a === void 0 ? void 0 : _a.getRunner()) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.title) || '') + Math.random();
|
152
|
+
const props = {
|
153
|
+
key,
|
154
|
+
};
|
155
|
+
const reactComponent = React__namespace.createElement(options.strict ? React__namespace.StrictMode : React__namespace.Fragment, props, jsx);
|
156
|
+
// since we always surround the component with a fragment
|
157
|
+
// let's get back the original component
|
158
|
+
const userComponent = reactComponent.props.children;
|
159
|
+
internalMountOptions.render(reactComponent, el, reactDomToUse);
|
160
|
+
return (cy.wrap(userComponent, { log: false })
|
161
|
+
.then(() => {
|
162
|
+
return cy.wrap({
|
163
|
+
component: userComponent,
|
164
|
+
rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
|
165
|
+
unmount: () => {
|
166
|
+
// @ts-expect-error - undocumented API
|
167
|
+
Cypress.utils.throwErrByPath('mount.unmount');
|
168
|
+
},
|
169
|
+
}, { log: false });
|
170
|
+
})
|
171
|
+
// by waiting, we delaying test execution for the next tick of event loop
|
172
|
+
// and letting hooks and component lifecycle methods to execute mount
|
173
|
+
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
|
174
|
+
.wait(0, { log: false })
|
175
|
+
.then(() => {
|
176
|
+
if (options.log !== false) {
|
177
|
+
// Get the display name property via the component constructor
|
178
|
+
// @ts-ignore FIXME
|
179
|
+
const componentName = getDisplayName(jsx);
|
180
|
+
const jsxComponentName = `<${componentName} ... />`;
|
181
|
+
Cypress.log({
|
182
|
+
name: type,
|
183
|
+
type: 'parent',
|
184
|
+
message: [jsxComponentName],
|
185
|
+
// @ts-ignore
|
186
|
+
$el: el.children.item(0),
|
187
|
+
consoleProps: () => {
|
188
|
+
return {
|
189
|
+
// @ts-ignore protect the use of jsx functional components use ReactNode
|
190
|
+
props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
|
191
|
+
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
|
192
|
+
home: 'https://github.com/cypress-io/cypress',
|
193
|
+
};
|
194
|
+
},
|
195
|
+
});
|
196
|
+
}
|
197
|
+
}));
|
198
|
+
// Bluebird types are terrible. I don't think the return type can be carried without this cast
|
199
|
+
});
|
200
|
+
};
|
201
|
+
/**
|
202
|
+
* Create an `unmount` function. Performs all the non-React-version specific
|
203
|
+
* behavior related to unmounting.
|
204
|
+
*
|
205
|
+
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
206
|
+
* or people writing adapters for third-party, custom adapters.
|
207
|
+
*
|
208
|
+
* @param {UnmountArgs} options used during unmounting
|
209
|
+
*/
|
210
|
+
const makeUnmountFn = (options) => {
|
211
|
+
return cy.then(() => {
|
212
|
+
var _a;
|
213
|
+
const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
214
|
+
if (wasUnmounted && options.log) {
|
215
|
+
Cypress.log({
|
216
|
+
name: 'unmount',
|
217
|
+
type: 'parent',
|
218
|
+
message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
|
219
|
+
consoleProps: () => {
|
220
|
+
return {
|
221
|
+
description: 'Unmounts React component',
|
222
|
+
parent: getContainerEl().parentNode,
|
223
|
+
home: 'https://github.com/cypress-io/cypress',
|
224
|
+
};
|
225
|
+
},
|
226
|
+
});
|
227
|
+
}
|
228
|
+
});
|
229
|
+
};
|
230
|
+
// Cleanup before each run
|
231
|
+
// NOTE: we cannot use unmount here because
|
232
|
+
// we are not in the context of a test
|
233
|
+
const preMountCleanup = () => {
|
234
|
+
mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
235
|
+
};
|
236
|
+
const _mount = (jsx, options = {}) => makeMountFn('mount', jsx, options);
|
237
|
+
const createMount = (defaultOptions) => {
|
238
|
+
return (element, options) => {
|
239
|
+
return _mount(element, Object.assign(Object.assign({}, defaultOptions), options));
|
240
|
+
};
|
241
|
+
};
|
242
|
+
// Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
|
243
|
+
// by creating an explicit function/import that the user can register in their 'component.js' support file,
|
244
|
+
// such as:
|
245
|
+
// import 'cypress/<my-framework>/support'
|
246
|
+
// or
|
247
|
+
// import { registerCT } from 'cypress/<my-framework>'
|
248
|
+
// registerCT()
|
249
|
+
// Note: This would be a breaking change
|
250
|
+
// it is required to unmount component in beforeEach hook in order to provide a clean state inside test
|
251
|
+
// because `mount` can be called after some preparation that can side effect unmount
|
252
|
+
// @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
|
253
253
|
setupHooks(preMountCleanup);
|
254
254
|
|
255
255
|
const debug = (
|
@@ -868,75 +868,75 @@ var semver = SemVer;
|
|
868
868
|
const major = (a, loose) => new semver(a, loose).major;
|
869
869
|
var major_1 = major;
|
870
870
|
|
871
|
-
let lastReactDom;
|
872
|
-
const cleanup = () => {
|
873
|
-
if (lastReactDom) {
|
874
|
-
const root = getContainerEl();
|
875
|
-
lastReactDom.unmountComponentAtNode(root);
|
876
|
-
return true;
|
877
|
-
}
|
878
|
-
return false;
|
879
|
-
};
|
880
|
-
/**
|
881
|
-
* Mounts a React component into the DOM.
|
882
|
-
* @param jsx {React.ReactNode} The React component to mount.
|
883
|
-
* @param options {MountOptions} [options={}] options to pass to the mount function.
|
884
|
-
* @param rerenderKey {string} [rerenderKey] A key to use to force a rerender.
|
885
|
-
* @see {@link https://on.cypress.io/mounting-react} for more details.
|
886
|
-
* @example
|
887
|
-
* import { mount } from '@cypress/react'
|
888
|
-
* import { Stepper } from './Stepper'
|
889
|
-
*
|
890
|
-
* it('mounts', () => {
|
891
|
-
* mount(<StepperComponent />)
|
892
|
-
* cy.get('[data-cy=increment]').click()
|
893
|
-
* cy.get('[data-cy=counter]').should('have.text', '1')
|
894
|
-
* }
|
895
|
-
*/
|
896
|
-
function mount(jsx, options = {}, rerenderKey) {
|
897
|
-
if (major_1(React.version) === 18) {
|
898
|
-
const message = '[cypress/react]: You are using `cypress/react`, which is designed for React <= 17. Consider changing to `cypress/react18`, which is designed for React 18.';
|
899
|
-
console.error(message);
|
900
|
-
Cypress.log({ name: 'warning', message });
|
901
|
-
}
|
902
|
-
// Remove last mounted component if cy.mount is called more than once in a test
|
903
|
-
cleanup();
|
904
|
-
const internalOptions = {
|
905
|
-
reactDom: ReactDOM,
|
906
|
-
render: (reactComponent, el, reactDomToUse) => {
|
907
|
-
lastReactDom = (reactDomToUse || ReactDOM);
|
908
|
-
return lastReactDom.render(reactComponent, el);
|
909
|
-
},
|
910
|
-
unmount: internalUnmount,
|
911
|
-
cleanup,
|
912
|
-
};
|
913
|
-
return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
|
914
|
-
}
|
915
|
-
/**
|
916
|
-
* Unmounts the component from the DOM.
|
917
|
-
* @internal
|
918
|
-
* @param options - Options for unmounting.
|
919
|
-
*/
|
920
|
-
function internalUnmount(options = { log: true }) {
|
921
|
-
return makeUnmountFn(options);
|
922
|
-
}
|
923
|
-
/**
|
924
|
-
* Removed as of Cypress 11.0.0.
|
925
|
-
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
926
|
-
*/
|
927
|
-
function unmount(options = { log: true }) {
|
928
|
-
// @ts-expect-error - undocumented API
|
929
|
-
Cypress.utils.throwErrByPath('mount.unmount');
|
871
|
+
let lastReactDom;
|
872
|
+
const cleanup = () => {
|
873
|
+
if (lastReactDom) {
|
874
|
+
const root = getContainerEl();
|
875
|
+
lastReactDom.unmountComponentAtNode(root);
|
876
|
+
return true;
|
877
|
+
}
|
878
|
+
return false;
|
879
|
+
};
|
880
|
+
/**
|
881
|
+
* Mounts a React component into the DOM.
|
882
|
+
* @param jsx {React.ReactNode} The React component to mount.
|
883
|
+
* @param options {MountOptions} [options={}] options to pass to the mount function.
|
884
|
+
* @param rerenderKey {string} [rerenderKey] A key to use to force a rerender.
|
885
|
+
* @see {@link https://on.cypress.io/mounting-react} for more details.
|
886
|
+
* @example
|
887
|
+
* import { mount } from '@cypress/react'
|
888
|
+
* import { Stepper } from './Stepper'
|
889
|
+
*
|
890
|
+
* it('mounts', () => {
|
891
|
+
* mount(<StepperComponent />)
|
892
|
+
* cy.get('[data-cy=increment]').click()
|
893
|
+
* cy.get('[data-cy=counter]').should('have.text', '1')
|
894
|
+
* }
|
895
|
+
*/
|
896
|
+
function mount(jsx, options = {}, rerenderKey) {
|
897
|
+
if (major_1(React.version) === 18) {
|
898
|
+
const message = '[cypress/react]: You are using `cypress/react`, which is designed for React <= 17. Consider changing to `cypress/react18`, which is designed for React 18.';
|
899
|
+
console.error(message);
|
900
|
+
Cypress.log({ name: 'warning', message });
|
901
|
+
}
|
902
|
+
// Remove last mounted component if cy.mount is called more than once in a test
|
903
|
+
cleanup();
|
904
|
+
const internalOptions = {
|
905
|
+
reactDom: ReactDOM,
|
906
|
+
render: (reactComponent, el, reactDomToUse) => {
|
907
|
+
lastReactDom = (reactDomToUse || ReactDOM);
|
908
|
+
return lastReactDom.render(reactComponent, el);
|
909
|
+
},
|
910
|
+
unmount: internalUnmount,
|
911
|
+
cleanup,
|
912
|
+
};
|
913
|
+
return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
|
914
|
+
}
|
915
|
+
/**
|
916
|
+
* Unmounts the component from the DOM.
|
917
|
+
* @internal
|
918
|
+
* @param options - Options for unmounting.
|
919
|
+
*/
|
920
|
+
function internalUnmount(options = { log: true }) {
|
921
|
+
return makeUnmountFn(options);
|
922
|
+
}
|
923
|
+
/**
|
924
|
+
* Removed as of Cypress 11.0.0.
|
925
|
+
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
926
|
+
*/
|
927
|
+
function unmount(options = { log: true }) {
|
928
|
+
// @ts-expect-error - undocumented API
|
929
|
+
Cypress.utils.throwErrByPath('mount.unmount');
|
930
930
|
}
|
931
931
|
|
932
|
-
/**
|
933
|
-
* Mounts a React hook function in a test component for testing.
|
934
|
-
* Removed as of Cypress 11.0.0.
|
935
|
-
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
936
|
-
*/
|
937
|
-
const mountHook = (hookFn) => {
|
938
|
-
// @ts-expect-error - internal API
|
939
|
-
Cypress.utils.throwErrByPath('mount.mount_hook');
|
932
|
+
/**
|
933
|
+
* Mounts a React hook function in a test component for testing.
|
934
|
+
* Removed as of Cypress 11.0.0.
|
935
|
+
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
936
|
+
*/
|
937
|
+
const mountHook = (hookFn) => {
|
938
|
+
// @ts-expect-error - internal API
|
939
|
+
Cypress.utils.throwErrByPath('mount.mount_hook');
|
940
940
|
};
|
941
941
|
|
942
942
|
exports.createMount = createMount;
|