cypress 13.10.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/types/net-stubbing.d.ts +101 -101
- 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
@@ -9,41 +9,41 @@ import * as React from 'react';
|
|
9
9
|
import React__default from 'react';
|
10
10
|
import ReactDOM from 'react-dom';
|
11
11
|
|
12
|
-
/**
|
13
|
-
* Gets the display name of the component when possible.
|
14
|
-
* @param type {JSX} The type object returned from creating the react element.
|
15
|
-
* @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
|
16
|
-
* @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
|
17
|
-
*/
|
18
|
-
function getDisplayName(node, fallbackName = 'Unknown') {
|
19
|
-
const type = node === null || node === void 0 ? void 0 : node.type;
|
20
|
-
if (!type) {
|
21
|
-
return fallbackName;
|
22
|
-
}
|
23
|
-
let displayName = null;
|
24
|
-
// The displayName property is not guaranteed to be a string.
|
25
|
-
// It's only safe to use for our purposes if it's a string.
|
26
|
-
// github.com/facebook/react-devtools/issues/803
|
27
|
-
if (typeof type.displayName === 'string') {
|
28
|
-
displayName = type.displayName;
|
29
|
-
}
|
30
|
-
if (!displayName) {
|
31
|
-
displayName = type.name || fallbackName;
|
32
|
-
}
|
33
|
-
// Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
|
34
|
-
// We need displayName with module name for error reports but it clutters the DevTools.
|
35
|
-
const match = displayName.match(/^(.*) \[from (.*)\]$/);
|
36
|
-
if (match) {
|
37
|
-
const componentName = match[1];
|
38
|
-
const moduleName = match[2];
|
39
|
-
if (componentName && moduleName) {
|
40
|
-
if (moduleName === componentName ||
|
41
|
-
moduleName.startsWith(`${componentName}.`)) {
|
42
|
-
displayName = componentName;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
return displayName;
|
12
|
+
/**
|
13
|
+
* Gets the display name of the component when possible.
|
14
|
+
* @param type {JSX} The type object returned from creating the react element.
|
15
|
+
* @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
|
16
|
+
* @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
|
17
|
+
*/
|
18
|
+
function getDisplayName(node, fallbackName = 'Unknown') {
|
19
|
+
const type = node === null || node === void 0 ? void 0 : node.type;
|
20
|
+
if (!type) {
|
21
|
+
return fallbackName;
|
22
|
+
}
|
23
|
+
let displayName = null;
|
24
|
+
// The displayName property is not guaranteed to be a string.
|
25
|
+
// It's only safe to use for our purposes if it's a string.
|
26
|
+
// github.com/facebook/react-devtools/issues/803
|
27
|
+
if (typeof type.displayName === 'string') {
|
28
|
+
displayName = type.displayName;
|
29
|
+
}
|
30
|
+
if (!displayName) {
|
31
|
+
displayName = type.name || fallbackName;
|
32
|
+
}
|
33
|
+
// Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
|
34
|
+
// We need displayName with module name for error reports but it clutters the DevTools.
|
35
|
+
const match = displayName.match(/^(.*) \[from (.*)\]$/);
|
36
|
+
if (match) {
|
37
|
+
const componentName = match[1];
|
38
|
+
const moduleName = match[2];
|
39
|
+
if (componentName && moduleName) {
|
40
|
+
if (moduleName === componentName ||
|
41
|
+
moduleName.startsWith(`${componentName}.`)) {
|
42
|
+
displayName = componentName;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return displayName;
|
47
47
|
}
|
48
48
|
|
49
49
|
const ROOT_SELECTOR = '[data-cy-root]';
|
@@ -95,141 +95,141 @@ function setupHooks(optionalCallback) {
|
|
95
95
|
});
|
96
96
|
}
|
97
97
|
|
98
|
-
let mountCleanup;
|
99
|
-
/**
|
100
|
-
* Create an `mount` function. Performs all the non-React-version specific
|
101
|
-
* behavior related to mounting. The React-version-specific code
|
102
|
-
* is injected. This helps us to maintain a consistent public API
|
103
|
-
* and handle breaking changes in React's rendering API.
|
104
|
-
*
|
105
|
-
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
106
|
-
* or people writing adapters for third-party, custom adapters.
|
107
|
-
*/
|
108
|
-
const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
|
109
|
-
if (!internalMountOptions) {
|
110
|
-
throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
|
111
|
-
}
|
112
|
-
// @ts-expect-error - this is removed but we want to check if a user is passing it, and error if they are.
|
113
|
-
if (options.alias) {
|
114
|
-
// @ts-expect-error
|
115
|
-
Cypress.utils.throwErrByPath('mount.alias', options.alias);
|
116
|
-
}
|
117
|
-
checkForRemovedStyleOptions(options);
|
118
|
-
mountCleanup = internalMountOptions.cleanup;
|
119
|
-
return cy
|
120
|
-
.then(() => {
|
121
|
-
var _a, _b, _c;
|
122
|
-
const reactDomToUse = internalMountOptions.reactDom;
|
123
|
-
const el = getContainerEl();
|
124
|
-
if (!el) {
|
125
|
-
throw new Error([
|
126
|
-
`[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
|
127
|
-
].join(' '));
|
128
|
-
}
|
129
|
-
const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
|
130
|
-
// @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
|
131
|
-
(((_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();
|
132
|
-
const props = {
|
133
|
-
key,
|
134
|
-
};
|
135
|
-
const reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
|
136
|
-
// since we always surround the component with a fragment
|
137
|
-
// let's get back the original component
|
138
|
-
const userComponent = reactComponent.props.children;
|
139
|
-
internalMountOptions.render(reactComponent, el, reactDomToUse);
|
140
|
-
return (cy.wrap(userComponent, { log: false })
|
141
|
-
.then(() => {
|
142
|
-
return cy.wrap({
|
143
|
-
component: userComponent,
|
144
|
-
rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
|
145
|
-
unmount: () => {
|
146
|
-
// @ts-expect-error - undocumented API
|
147
|
-
Cypress.utils.throwErrByPath('mount.unmount');
|
148
|
-
},
|
149
|
-
}, { log: false });
|
150
|
-
})
|
151
|
-
// by waiting, we delaying test execution for the next tick of event loop
|
152
|
-
// and letting hooks and component lifecycle methods to execute mount
|
153
|
-
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
|
154
|
-
.wait(0, { log: false })
|
155
|
-
.then(() => {
|
156
|
-
if (options.log !== false) {
|
157
|
-
// Get the display name property via the component constructor
|
158
|
-
// @ts-ignore FIXME
|
159
|
-
const componentName = getDisplayName(jsx);
|
160
|
-
const jsxComponentName = `<${componentName} ... />`;
|
161
|
-
Cypress.log({
|
162
|
-
name: type,
|
163
|
-
type: 'parent',
|
164
|
-
message: [jsxComponentName],
|
165
|
-
// @ts-ignore
|
166
|
-
$el: el.children.item(0),
|
167
|
-
consoleProps: () => {
|
168
|
-
return {
|
169
|
-
// @ts-ignore protect the use of jsx functional components use ReactNode
|
170
|
-
props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
|
171
|
-
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
|
172
|
-
home: 'https://github.com/cypress-io/cypress',
|
173
|
-
};
|
174
|
-
},
|
175
|
-
});
|
176
|
-
}
|
177
|
-
}));
|
178
|
-
// Bluebird types are terrible. I don't think the return type can be carried without this cast
|
179
|
-
});
|
180
|
-
};
|
181
|
-
/**
|
182
|
-
* Create an `unmount` function. Performs all the non-React-version specific
|
183
|
-
* behavior related to unmounting.
|
184
|
-
*
|
185
|
-
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
186
|
-
* or people writing adapters for third-party, custom adapters.
|
187
|
-
*
|
188
|
-
* @param {UnmountArgs} options used during unmounting
|
189
|
-
*/
|
190
|
-
const makeUnmountFn = (options) => {
|
191
|
-
return cy.then(() => {
|
192
|
-
var _a;
|
193
|
-
const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
194
|
-
if (wasUnmounted && options.log) {
|
195
|
-
Cypress.log({
|
196
|
-
name: 'unmount',
|
197
|
-
type: 'parent',
|
198
|
-
message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
|
199
|
-
consoleProps: () => {
|
200
|
-
return {
|
201
|
-
description: 'Unmounts React component',
|
202
|
-
parent: getContainerEl().parentNode,
|
203
|
-
home: 'https://github.com/cypress-io/cypress',
|
204
|
-
};
|
205
|
-
},
|
206
|
-
});
|
207
|
-
}
|
208
|
-
});
|
209
|
-
};
|
210
|
-
// Cleanup before each run
|
211
|
-
// NOTE: we cannot use unmount here because
|
212
|
-
// we are not in the context of a test
|
213
|
-
const preMountCleanup = () => {
|
214
|
-
mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
215
|
-
};
|
216
|
-
const _mount = (jsx, options = {}) => makeMountFn('mount', jsx, options);
|
217
|
-
const createMount = (defaultOptions) => {
|
218
|
-
return (element, options) => {
|
219
|
-
return _mount(element, Object.assign(Object.assign({}, defaultOptions), options));
|
220
|
-
};
|
221
|
-
};
|
222
|
-
// Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
|
223
|
-
// by creating an explicit function/import that the user can register in their 'component.js' support file,
|
224
|
-
// such as:
|
225
|
-
// import 'cypress/<my-framework>/support'
|
226
|
-
// or
|
227
|
-
// import { registerCT } from 'cypress/<my-framework>'
|
228
|
-
// registerCT()
|
229
|
-
// Note: This would be a breaking change
|
230
|
-
// it is required to unmount component in beforeEach hook in order to provide a clean state inside test
|
231
|
-
// because `mount` can be called after some preparation that can side effect unmount
|
232
|
-
// @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
|
98
|
+
let mountCleanup;
|
99
|
+
/**
|
100
|
+
* Create an `mount` function. Performs all the non-React-version specific
|
101
|
+
* behavior related to mounting. The React-version-specific code
|
102
|
+
* is injected. This helps us to maintain a consistent public API
|
103
|
+
* and handle breaking changes in React's rendering API.
|
104
|
+
*
|
105
|
+
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
106
|
+
* or people writing adapters for third-party, custom adapters.
|
107
|
+
*/
|
108
|
+
const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
|
109
|
+
if (!internalMountOptions) {
|
110
|
+
throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
|
111
|
+
}
|
112
|
+
// @ts-expect-error - this is removed but we want to check if a user is passing it, and error if they are.
|
113
|
+
if (options.alias) {
|
114
|
+
// @ts-expect-error
|
115
|
+
Cypress.utils.throwErrByPath('mount.alias', options.alias);
|
116
|
+
}
|
117
|
+
checkForRemovedStyleOptions(options);
|
118
|
+
mountCleanup = internalMountOptions.cleanup;
|
119
|
+
return cy
|
120
|
+
.then(() => {
|
121
|
+
var _a, _b, _c;
|
122
|
+
const reactDomToUse = internalMountOptions.reactDom;
|
123
|
+
const el = getContainerEl();
|
124
|
+
if (!el) {
|
125
|
+
throw new Error([
|
126
|
+
`[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
|
127
|
+
].join(' '));
|
128
|
+
}
|
129
|
+
const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
|
130
|
+
// @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
|
131
|
+
(((_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();
|
132
|
+
const props = {
|
133
|
+
key,
|
134
|
+
};
|
135
|
+
const reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
|
136
|
+
// since we always surround the component with a fragment
|
137
|
+
// let's get back the original component
|
138
|
+
const userComponent = reactComponent.props.children;
|
139
|
+
internalMountOptions.render(reactComponent, el, reactDomToUse);
|
140
|
+
return (cy.wrap(userComponent, { log: false })
|
141
|
+
.then(() => {
|
142
|
+
return cy.wrap({
|
143
|
+
component: userComponent,
|
144
|
+
rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
|
145
|
+
unmount: () => {
|
146
|
+
// @ts-expect-error - undocumented API
|
147
|
+
Cypress.utils.throwErrByPath('mount.unmount');
|
148
|
+
},
|
149
|
+
}, { log: false });
|
150
|
+
})
|
151
|
+
// by waiting, we delaying test execution for the next tick of event loop
|
152
|
+
// and letting hooks and component lifecycle methods to execute mount
|
153
|
+
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
|
154
|
+
.wait(0, { log: false })
|
155
|
+
.then(() => {
|
156
|
+
if (options.log !== false) {
|
157
|
+
// Get the display name property via the component constructor
|
158
|
+
// @ts-ignore FIXME
|
159
|
+
const componentName = getDisplayName(jsx);
|
160
|
+
const jsxComponentName = `<${componentName} ... />`;
|
161
|
+
Cypress.log({
|
162
|
+
name: type,
|
163
|
+
type: 'parent',
|
164
|
+
message: [jsxComponentName],
|
165
|
+
// @ts-ignore
|
166
|
+
$el: el.children.item(0),
|
167
|
+
consoleProps: () => {
|
168
|
+
return {
|
169
|
+
// @ts-ignore protect the use of jsx functional components use ReactNode
|
170
|
+
props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
|
171
|
+
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
|
172
|
+
home: 'https://github.com/cypress-io/cypress',
|
173
|
+
};
|
174
|
+
},
|
175
|
+
});
|
176
|
+
}
|
177
|
+
}));
|
178
|
+
// Bluebird types are terrible. I don't think the return type can be carried without this cast
|
179
|
+
});
|
180
|
+
};
|
181
|
+
/**
|
182
|
+
* Create an `unmount` function. Performs all the non-React-version specific
|
183
|
+
* behavior related to unmounting.
|
184
|
+
*
|
185
|
+
* This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
|
186
|
+
* or people writing adapters for third-party, custom adapters.
|
187
|
+
*
|
188
|
+
* @param {UnmountArgs} options used during unmounting
|
189
|
+
*/
|
190
|
+
const makeUnmountFn = (options) => {
|
191
|
+
return cy.then(() => {
|
192
|
+
var _a;
|
193
|
+
const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
194
|
+
if (wasUnmounted && options.log) {
|
195
|
+
Cypress.log({
|
196
|
+
name: 'unmount',
|
197
|
+
type: 'parent',
|
198
|
+
message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
|
199
|
+
consoleProps: () => {
|
200
|
+
return {
|
201
|
+
description: 'Unmounts React component',
|
202
|
+
parent: getContainerEl().parentNode,
|
203
|
+
home: 'https://github.com/cypress-io/cypress',
|
204
|
+
};
|
205
|
+
},
|
206
|
+
});
|
207
|
+
}
|
208
|
+
});
|
209
|
+
};
|
210
|
+
// Cleanup before each run
|
211
|
+
// NOTE: we cannot use unmount here because
|
212
|
+
// we are not in the context of a test
|
213
|
+
const preMountCleanup = () => {
|
214
|
+
mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
|
215
|
+
};
|
216
|
+
const _mount = (jsx, options = {}) => makeMountFn('mount', jsx, options);
|
217
|
+
const createMount = (defaultOptions) => {
|
218
|
+
return (element, options) => {
|
219
|
+
return _mount(element, Object.assign(Object.assign({}, defaultOptions), options));
|
220
|
+
};
|
221
|
+
};
|
222
|
+
// Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
|
223
|
+
// by creating an explicit function/import that the user can register in their 'component.js' support file,
|
224
|
+
// such as:
|
225
|
+
// import 'cypress/<my-framework>/support'
|
226
|
+
// or
|
227
|
+
// import { registerCT } from 'cypress/<my-framework>'
|
228
|
+
// registerCT()
|
229
|
+
// Note: This would be a breaking change
|
230
|
+
// it is required to unmount component in beforeEach hook in order to provide a clean state inside test
|
231
|
+
// because `mount` can be called after some preparation that can side effect unmount
|
232
|
+
// @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
|
233
233
|
setupHooks(preMountCleanup);
|
234
234
|
|
235
235
|
const debug = (
|
@@ -848,75 +848,75 @@ var semver = SemVer;
|
|
848
848
|
const major = (a, loose) => new semver(a, loose).major;
|
849
849
|
var major_1 = major;
|
850
850
|
|
851
|
-
let lastReactDom;
|
852
|
-
const cleanup = () => {
|
853
|
-
if (lastReactDom) {
|
854
|
-
const root = getContainerEl();
|
855
|
-
lastReactDom.unmountComponentAtNode(root);
|
856
|
-
return true;
|
857
|
-
}
|
858
|
-
return false;
|
859
|
-
};
|
860
|
-
/**
|
861
|
-
* Mounts a React component into the DOM.
|
862
|
-
* @param jsx {React.ReactNode} The React component to mount.
|
863
|
-
* @param options {MountOptions} [options={}] options to pass to the mount function.
|
864
|
-
* @param rerenderKey {string} [rerenderKey] A key to use to force a rerender.
|
865
|
-
* @see {@link https://on.cypress.io/mounting-react} for more details.
|
866
|
-
* @example
|
867
|
-
* import { mount } from '@cypress/react'
|
868
|
-
* import { Stepper } from './Stepper'
|
869
|
-
*
|
870
|
-
* it('mounts', () => {
|
871
|
-
* mount(<StepperComponent />)
|
872
|
-
* cy.get('[data-cy=increment]').click()
|
873
|
-
* cy.get('[data-cy=counter]').should('have.text', '1')
|
874
|
-
* }
|
875
|
-
*/
|
876
|
-
function mount(jsx, options = {}, rerenderKey) {
|
877
|
-
if (major_1(React__default.version) === 18) {
|
878
|
-
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.';
|
879
|
-
console.error(message);
|
880
|
-
Cypress.log({ name: 'warning', message });
|
881
|
-
}
|
882
|
-
// Remove last mounted component if cy.mount is called more than once in a test
|
883
|
-
cleanup();
|
884
|
-
const internalOptions = {
|
885
|
-
reactDom: ReactDOM,
|
886
|
-
render: (reactComponent, el, reactDomToUse) => {
|
887
|
-
lastReactDom = (reactDomToUse || ReactDOM);
|
888
|
-
return lastReactDom.render(reactComponent, el);
|
889
|
-
},
|
890
|
-
unmount: internalUnmount,
|
891
|
-
cleanup,
|
892
|
-
};
|
893
|
-
return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
|
894
|
-
}
|
895
|
-
/**
|
896
|
-
* Unmounts the component from the DOM.
|
897
|
-
* @internal
|
898
|
-
* @param options - Options for unmounting.
|
899
|
-
*/
|
900
|
-
function internalUnmount(options = { log: true }) {
|
901
|
-
return makeUnmountFn(options);
|
902
|
-
}
|
903
|
-
/**
|
904
|
-
* Removed as of Cypress 11.0.0.
|
905
|
-
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
906
|
-
*/
|
907
|
-
function unmount(options = { log: true }) {
|
908
|
-
// @ts-expect-error - undocumented API
|
909
|
-
Cypress.utils.throwErrByPath('mount.unmount');
|
851
|
+
let lastReactDom;
|
852
|
+
const cleanup = () => {
|
853
|
+
if (lastReactDom) {
|
854
|
+
const root = getContainerEl();
|
855
|
+
lastReactDom.unmountComponentAtNode(root);
|
856
|
+
return true;
|
857
|
+
}
|
858
|
+
return false;
|
859
|
+
};
|
860
|
+
/**
|
861
|
+
* Mounts a React component into the DOM.
|
862
|
+
* @param jsx {React.ReactNode} The React component to mount.
|
863
|
+
* @param options {MountOptions} [options={}] options to pass to the mount function.
|
864
|
+
* @param rerenderKey {string} [rerenderKey] A key to use to force a rerender.
|
865
|
+
* @see {@link https://on.cypress.io/mounting-react} for more details.
|
866
|
+
* @example
|
867
|
+
* import { mount } from '@cypress/react'
|
868
|
+
* import { Stepper } from './Stepper'
|
869
|
+
*
|
870
|
+
* it('mounts', () => {
|
871
|
+
* mount(<StepperComponent />)
|
872
|
+
* cy.get('[data-cy=increment]').click()
|
873
|
+
* cy.get('[data-cy=counter]').should('have.text', '1')
|
874
|
+
* }
|
875
|
+
*/
|
876
|
+
function mount(jsx, options = {}, rerenderKey) {
|
877
|
+
if (major_1(React__default.version) === 18) {
|
878
|
+
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.';
|
879
|
+
console.error(message);
|
880
|
+
Cypress.log({ name: 'warning', message });
|
881
|
+
}
|
882
|
+
// Remove last mounted component if cy.mount is called more than once in a test
|
883
|
+
cleanup();
|
884
|
+
const internalOptions = {
|
885
|
+
reactDom: ReactDOM,
|
886
|
+
render: (reactComponent, el, reactDomToUse) => {
|
887
|
+
lastReactDom = (reactDomToUse || ReactDOM);
|
888
|
+
return lastReactDom.render(reactComponent, el);
|
889
|
+
},
|
890
|
+
unmount: internalUnmount,
|
891
|
+
cleanup,
|
892
|
+
};
|
893
|
+
return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
|
894
|
+
}
|
895
|
+
/**
|
896
|
+
* Unmounts the component from the DOM.
|
897
|
+
* @internal
|
898
|
+
* @param options - Options for unmounting.
|
899
|
+
*/
|
900
|
+
function internalUnmount(options = { log: true }) {
|
901
|
+
return makeUnmountFn(options);
|
902
|
+
}
|
903
|
+
/**
|
904
|
+
* Removed as of Cypress 11.0.0.
|
905
|
+
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
906
|
+
*/
|
907
|
+
function unmount(options = { log: true }) {
|
908
|
+
// @ts-expect-error - undocumented API
|
909
|
+
Cypress.utils.throwErrByPath('mount.unmount');
|
910
910
|
}
|
911
911
|
|
912
|
-
/**
|
913
|
-
* Mounts a React hook function in a test component for testing.
|
914
|
-
* Removed as of Cypress 11.0.0.
|
915
|
-
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
916
|
-
*/
|
917
|
-
const mountHook = (hookFn) => {
|
918
|
-
// @ts-expect-error - internal API
|
919
|
-
Cypress.utils.throwErrByPath('mount.mount_hook');
|
912
|
+
/**
|
913
|
+
* Mounts a React hook function in a test component for testing.
|
914
|
+
* Removed as of Cypress 11.0.0.
|
915
|
+
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
|
916
|
+
*/
|
917
|
+
const mountHook = (hookFn) => {
|
918
|
+
// @ts-expect-error - internal API
|
919
|
+
Cypress.utils.throwErrByPath('mount.mount_hook');
|
920
920
|
};
|
921
921
|
|
922
922
|
export { createMount, getContainerEl, makeMountFn, makeUnmountFn, mount, mountHook, unmount };
|
package/react/dist/index.d.ts
CHANGED
@@ -8,7 +8,7 @@ interface UnmountArgs {
|
|
8
8
|
log: boolean;
|
9
9
|
boundComponentMessage?: string;
|
10
10
|
}
|
11
|
-
|
11
|
+
type MountOptions = Partial<MountReactComponentOptions>;
|
12
12
|
interface MountReactComponentOptions {
|
13
13
|
ReactDom: typeof react_dom;
|
14
14
|
/**
|
package/react/package.json
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
"devDependencies": {
|
19
19
|
"@cypress/mount-utils": "0.0.0-development",
|
20
20
|
"@types/semver": "7.5.0",
|
21
|
-
"@vitejs/plugin-react": "4.
|
21
|
+
"@vitejs/plugin-react": "4.3.0",
|
22
22
|
"axios": "0.21.2",
|
23
23
|
"cypress": "0.0.0-development",
|
24
24
|
"prop-types": "15.7.2",
|
@@ -27,8 +27,8 @@
|
|
27
27
|
"react-router": "6.0.0-alpha.1",
|
28
28
|
"react-router-dom": "6.0.0-alpha.1",
|
29
29
|
"semver": "^7.5.3",
|
30
|
-
"typescript": "
|
31
|
-
"vite": "
|
30
|
+
"typescript": "~5.4.5",
|
31
|
+
"vite": "5.2.11",
|
32
32
|
"vite-plugin-require-transform": "1.0.12"
|
33
33
|
},
|
34
34
|
"peerDependencies": {
|