cypress 9.7.0 → 10.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/index.mjs +15 -0
  2. package/lib/cli.js +72 -23
  3. package/lib/errors.js +16 -1
  4. package/lib/exec/open.js +45 -10
  5. package/lib/exec/run.js +17 -10
  6. package/lib/exec/shared.js +30 -9
  7. package/lib/exec/spawn.js +4 -0
  8. package/lib/exec/xvfb.js +1 -0
  9. package/lib/util.js +10 -3
  10. package/mount-utils/CHANGELOG.md +20 -0
  11. package/mount-utils/README.md +14 -0
  12. package/mount-utils/dist/index.d.ts +54 -0
  13. package/mount-utils/dist/index.js +134 -0
  14. package/mount-utils/package.json +31 -0
  15. package/package.json +39 -4
  16. package/react/CHANGELOG.md +373 -0
  17. package/react/README.md +414 -0
  18. package/react/dist/cypress-react.browser.js +497 -0
  19. package/react/dist/cypress-react.cjs.js +495 -0
  20. package/react/dist/cypress-react.esm-bundler.js +467 -0
  21. package/react/dist/getDisplayName.d.ts +8 -0
  22. package/react/dist/index.d.ts +2 -0
  23. package/react/dist/mount.d.ts +143 -0
  24. package/react/dist/mountHook.d.ts +11 -0
  25. package/react/package.json +105 -0
  26. package/types/bluebird/index.d.ts +18 -4
  27. package/types/cypress-npm-api.d.ts +4 -10
  28. package/types/cypress.d.ts +172 -120
  29. package/types/minimatch/index.d.ts +15 -5
  30. package/vue/CHANGELOG.md +380 -0
  31. package/vue/README.md +678 -0
  32. package/vue/dist/cypress-vue.cjs.js +13535 -0
  33. package/vue/dist/cypress-vue.esm-bundler.js +13511 -0
  34. package/vue/dist/index.d.ts +56 -0
  35. package/vue/package.json +86 -0
  36. package/vue2/CHANGELOG.md +5 -0
  37. package/vue2/README.md +693 -0
  38. package/vue2/dist/cypress-vue2.browser.js +20191 -0
  39. package/vue2/dist/cypress-vue2.cjs.js +20188 -0
  40. package/vue2/dist/cypress-vue2.esm-bundler.js +20179 -0
  41. package/vue2/dist/index.d.ts +171 -0
  42. package/vue2/package.json +59 -0
@@ -0,0 +1,467 @@
1
+
2
+ /**
3
+ * @cypress/react v0.0.0-development
4
+ * (c) 2022 Cypress.io
5
+ * Released under the MIT License
6
+ */
7
+
8
+ import * as React from 'react';
9
+ import * as ReactDOM from 'react-dom';
10
+
11
+ /*! *****************************************************************************
12
+ Copyright (c) Microsoft Corporation.
13
+
14
+ Permission to use, copy, modify, and/or distribute this software for any
15
+ purpose with or without fee is hereby granted.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
+ PERFORMANCE OF THIS SOFTWARE.
24
+ ***************************************************************************** */
25
+
26
+ var __assign = function() {
27
+ __assign = Object.assign || function __assign(t) {
28
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29
+ s = arguments[i];
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
31
+ }
32
+ return t;
33
+ };
34
+ return __assign.apply(this, arguments);
35
+ };
36
+
37
+ var cachedDisplayNames = new WeakMap();
38
+ /**
39
+ * Gets the display name of the component when possible.
40
+ * @param type {JSX} The type object returned from creating the react element.
41
+ * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
42
+ * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
43
+ */
44
+ function getDisplayName(type, fallbackName) {
45
+ if (fallbackName === void 0) { fallbackName = 'Unknown'; }
46
+ var nameFromCache = cachedDisplayNames.get(type);
47
+ if (nameFromCache != null) {
48
+ return nameFromCache;
49
+ }
50
+ var displayName = null;
51
+ // The displayName property is not guaranteed to be a string.
52
+ // It's only safe to use for our purposes if it's a string.
53
+ // github.com/facebook/react-devtools/issues/803
54
+ if (typeof type.displayName === 'string') {
55
+ displayName = type.displayName;
56
+ }
57
+ if (!displayName) {
58
+ displayName = type.name || fallbackName;
59
+ }
60
+ // Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
61
+ // We need displayName with module name for error reports but it clutters the DevTools.
62
+ var match = displayName.match(/^(.*) \[from (.*)\]$/);
63
+ if (match) {
64
+ var componentName = match[1];
65
+ var moduleName = match[2];
66
+ if (componentName && moduleName) {
67
+ if (moduleName === componentName ||
68
+ moduleName.startsWith(componentName + ".")) {
69
+ displayName = componentName;
70
+ }
71
+ }
72
+ }
73
+ try {
74
+ cachedDisplayNames.set(type, displayName);
75
+ }
76
+ catch (e) {
77
+ // do nothing
78
+ }
79
+ return displayName;
80
+ }
81
+
82
+ const ROOT_SELECTOR = '[data-cy-root]';
83
+ const getContainerEl = () => {
84
+ const el = document.querySelector(ROOT_SELECTOR);
85
+ if (el) {
86
+ return el;
87
+ }
88
+ throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please use the mount utils to mount it properly`);
89
+ };
90
+ /**
91
+ * Remove any style or extra link elements from the iframe placeholder
92
+ * left from any previous test
93
+ *
94
+ */
95
+ function cleanupStyles() {
96
+ const styles = document.body.querySelectorAll('[data-cy=injected-style-tag]');
97
+ styles.forEach((styleElement) => {
98
+ if (styleElement.parentElement) {
99
+ styleElement.parentElement.removeChild(styleElement);
100
+ }
101
+ });
102
+ const links = document.body.querySelectorAll('[data-cy=injected-stylesheet]');
103
+ links.forEach((link) => {
104
+ if (link.parentElement) {
105
+ link.parentElement.removeChild(link);
106
+ }
107
+ });
108
+ }
109
+ /**
110
+ * Insert links to external style resources.
111
+ */
112
+ function insertStylesheets(stylesheets, document, el) {
113
+ stylesheets.forEach((href) => {
114
+ const link = document.createElement('link');
115
+ link.type = 'text/css';
116
+ link.rel = 'stylesheet';
117
+ link.href = href;
118
+ link.dataset.cy = 'injected-stylesheet';
119
+ document.body.insertBefore(link, el);
120
+ });
121
+ }
122
+ /**
123
+ * Inserts a single stylesheet element
124
+ */
125
+ function insertStyles(styles, document, el) {
126
+ styles.forEach((style) => {
127
+ const styleElement = document.createElement('style');
128
+ styleElement.dataset.cy = 'injected-style-tag';
129
+ styleElement.appendChild(document.createTextNode(style));
130
+ document.body.insertBefore(styleElement, el);
131
+ });
132
+ }
133
+ function insertSingleCssFile(cssFilename, document, el, log) {
134
+ return cy.readFile(cssFilename, { log }).then((css) => {
135
+ const style = document.createElement('style');
136
+ style.appendChild(document.createTextNode(css));
137
+ document.body.insertBefore(style, el);
138
+ });
139
+ }
140
+ /**
141
+ * Reads the given CSS file from local file system
142
+ * and adds the loaded style text as an element.
143
+ */
144
+ function insertLocalCssFiles(cssFilenames, document, el, log) {
145
+ return Cypress.Promise.mapSeries(cssFilenames, (cssFilename) => {
146
+ return insertSingleCssFile(cssFilename, document, el, log);
147
+ });
148
+ }
149
+ /**
150
+ * Injects custom style text or CSS file or 3rd party style resources
151
+ * into the given document.
152
+ */
153
+ const injectStylesBeforeElement = (options, document, el) => {
154
+ if (!el)
155
+ return;
156
+ // first insert all stylesheets as Link elements
157
+ let stylesheets = [];
158
+ if (typeof options.stylesheet === 'string') {
159
+ stylesheets.push(options.stylesheet);
160
+ }
161
+ else if (Array.isArray(options.stylesheet)) {
162
+ stylesheets = stylesheets.concat(options.stylesheet);
163
+ }
164
+ if (typeof options.stylesheets === 'string') {
165
+ options.stylesheets = [options.stylesheets];
166
+ }
167
+ if (options.stylesheets) {
168
+ stylesheets = stylesheets.concat(options.stylesheets);
169
+ }
170
+ insertStylesheets(stylesheets, document, el);
171
+ // insert any styles as <style>...</style> elements
172
+ let styles = [];
173
+ if (typeof options.style === 'string') {
174
+ styles.push(options.style);
175
+ }
176
+ else if (Array.isArray(options.style)) {
177
+ styles = styles.concat(options.style);
178
+ }
179
+ if (typeof options.styles === 'string') {
180
+ styles.push(options.styles);
181
+ }
182
+ else if (Array.isArray(options.styles)) {
183
+ styles = styles.concat(options.styles);
184
+ }
185
+ insertStyles(styles, document, el);
186
+ // now load any css files by path and add their content
187
+ // as <style>...</style> elements
188
+ let cssFiles = [];
189
+ if (typeof options.cssFile === 'string') {
190
+ cssFiles.push(options.cssFile);
191
+ }
192
+ else if (Array.isArray(options.cssFile)) {
193
+ cssFiles = cssFiles.concat(options.cssFile);
194
+ }
195
+ if (typeof options.cssFiles === 'string') {
196
+ cssFiles.push(options.cssFiles);
197
+ }
198
+ else if (Array.isArray(options.cssFiles)) {
199
+ cssFiles = cssFiles.concat(options.cssFiles);
200
+ }
201
+ return insertLocalCssFiles(cssFiles, document, el, options.log);
202
+ };
203
+ function setupHooks(optionalCallback) {
204
+ // When running component specs, we cannot allow "cy.visit"
205
+ // because it will wipe out our preparation work, and does not make much sense
206
+ // thus we overwrite "cy.visit" to throw an error
207
+ Cypress.Commands.overwrite('visit', () => {
208
+ throw new Error('cy.visit from a component spec is not allowed');
209
+ });
210
+ // @ts-ignore
211
+ Cypress.on('test:before:run', () => {
212
+ optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
213
+ cleanupStyles();
214
+ });
215
+ }
216
+
217
+ /**
218
+ * Inject custom style text or CSS file or 3rd party style resources
219
+ */
220
+ var injectStyles = function (options) {
221
+ return function () {
222
+ var el = getContainerEl();
223
+ return injectStylesBeforeElement(options, document, el);
224
+ };
225
+ };
226
+ /**
227
+ * Mount a React component in a blank document; register it as an alias
228
+ * To access: use an alias or original component reference
229
+ * @function mount
230
+ * @param {React.ReactElement} jsx - component to mount
231
+ * @param {MountOptions} [options] - options, like alias, styles
232
+ * @see https://github.com/bahmutov/@cypress/react
233
+ * @see https://glebbahmutov.com/blog/my-vision-for-component-tests/
234
+ * @example
235
+ ```
236
+ import Hello from './hello.jsx'
237
+ import { mount } from '@cypress/react'
238
+ it('works', () => {
239
+ mount(<Hello onClick={cy.stub()} />)
240
+ // use Cypress commands
241
+ cy.contains('Hello').click()
242
+ })
243
+ ```
244
+ **/
245
+ var mount = function (jsx, options) {
246
+ if (options === void 0) { options = {}; }
247
+ return _mount('mount', jsx, options);
248
+ };
249
+ var lastMountedReactDom;
250
+ /**
251
+ * @see `mount`
252
+ * @param type The type of mount executed
253
+ * @param rerenderKey If specified, use the provided key rather than generating a new one
254
+ */
255
+ var _mount = function (type, jsx, options, rerenderKey) {
256
+ if (options === void 0) { options = {}; }
257
+ // Get the display name property via the component constructor
258
+ // @ts-ignore FIXME
259
+ var componentName = getDisplayName(jsx.type, options.alias);
260
+ var displayName = options.alias || componentName;
261
+ var jsxComponentName = "<" + componentName + " ... />";
262
+ var message = options.alias
263
+ ? jsxComponentName + " as \"" + options.alias + "\""
264
+ : jsxComponentName;
265
+ return cy
266
+ .then(injectStyles(options))
267
+ .then(function () {
268
+ var _a, _b, _c;
269
+ var reactDomToUse = options.ReactDom || ReactDOM;
270
+ lastMountedReactDom = reactDomToUse;
271
+ var el = getContainerEl();
272
+ if (!el) {
273
+ throw new Error([
274
+ "[@cypress/react] \uD83D\uDD25 Hmm, cannot find root element to mount the component. Searched for " + ROOT_SELECTOR,
275
+ ].join(' '));
276
+ }
277
+ var key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
278
+ // @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
279
+ (((_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();
280
+ var props = {
281
+ key: key,
282
+ };
283
+ var reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
284
+ // since we always surround the component with a fragment
285
+ // let's get back the original component
286
+ var userComponent = reactComponent.props.children;
287
+ reactDomToUse.render(reactComponent, el);
288
+ if (options.log !== false) {
289
+ Cypress.log({
290
+ name: type,
291
+ type: 'parent',
292
+ message: [message],
293
+ // @ts-ignore
294
+ $el: el.children.item(0),
295
+ consoleProps: function () {
296
+ return {
297
+ // @ts-ignore protect the use of jsx functional components use ReactNode
298
+ props: jsx.props,
299
+ description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
300
+ home: 'https://github.com/cypress-io/cypress',
301
+ };
302
+ },
303
+ }).snapshot('mounted').end();
304
+ }
305
+ return (
306
+ // Separate alias and returned value. Alias returns the component only, and the thenable returns the additional functions
307
+ cy.wrap(userComponent, { log: false })
308
+ .as(displayName)
309
+ .then(function () {
310
+ return cy.wrap({
311
+ component: userComponent,
312
+ rerender: function (newComponent) { return _mount('rerender', newComponent, options, key); },
313
+ unmount: function () { return _unmount({ boundComponentMessage: jsxComponentName, log: true }); },
314
+ }, { log: false });
315
+ })
316
+ // by waiting, we delaying test execution for the next tick of event loop
317
+ // and letting hooks and component lifecycle methods to execute mount
318
+ // https://github.com/bahmutov/cypress-react-unit-test/issues/200
319
+ .wait(0, { log: false }));
320
+ // Bluebird types are terrible. I don't think the return type can be carried without this cast
321
+ });
322
+ };
323
+ /**
324
+ * Removes the mounted component. Notice this command automatically
325
+ * queues up the `unmount` into Cypress chain, thus you don't need `.then`
326
+ * to call it.
327
+ * @see https://github.com/cypress-io/cypress/tree/develop/npm/react/cypress/component/basic/unmount
328
+ * @example
329
+ ```
330
+ import { mount, unmount } from '@cypress/react'
331
+ it('works', () => {
332
+ mount(...)
333
+ // interact with the component using Cypress commands
334
+ // whenever you want to unmount
335
+ unmount()
336
+ })
337
+ ```
338
+ */
339
+ // @ts-ignore
340
+ var unmount = function (options) {
341
+ if (options === void 0) { options = { log: true }; }
342
+ return _unmount(options);
343
+ };
344
+ var _unmount = function (options) {
345
+ return cy.then(function () {
346
+ return cy.get(ROOT_SELECTOR, { log: false }).then(function ($el) {
347
+ var _a;
348
+ if (lastMountedReactDom) {
349
+ var wasUnmounted = lastMountedReactDom.unmountComponentAtNode($el[0]);
350
+ if (wasUnmounted && options.log) {
351
+ Cypress.log({
352
+ name: 'unmount',
353
+ type: 'parent',
354
+ message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
355
+ consoleProps: function () {
356
+ return {
357
+ description: 'Unmounts React component',
358
+ parent: $el[0],
359
+ home: 'https://github.com/cypress-io/cypress',
360
+ };
361
+ },
362
+ });
363
+ }
364
+ }
365
+ });
366
+ });
367
+ };
368
+ // Cleanup before each run
369
+ // NOTE: we cannot use unmount here because
370
+ // we are not in the context of a test
371
+ var preMountCleanup = function () {
372
+ var el = getContainerEl();
373
+ if (el && lastMountedReactDom) {
374
+ lastMountedReactDom.unmountComponentAtNode(el);
375
+ }
376
+ };
377
+ /**
378
+ * Creates new instance of `mount` function with default options
379
+ * @function createMount
380
+ * @param {MountOptions} [defaultOptions] - defaultOptions for returned `mount` function
381
+ * @returns new instance of `mount` with assigned options
382
+ * @example
383
+ * ```
384
+ * import Hello from './hello.jsx'
385
+ * import { createMount } from '@cypress/react'
386
+ *
387
+ * const mount = createMount({ strict: true, cssFile: 'path/to/any/css/file.css' })
388
+ *
389
+ * it('works', () => {
390
+ * mount(<Hello />)
391
+ * // use Cypress commands
392
+ * cy.get('button').should('have.css', 'color', 'rgb(124, 12, 109)')
393
+ * })
394
+ ```
395
+ **/
396
+ var createMount = function (defaultOptions) {
397
+ return function (element, options) {
398
+ return mount(element, __assign(__assign({}, defaultOptions), options));
399
+ };
400
+ };
401
+ // it is required to unmount component in beforeEach hook in order to provide a clean state inside test
402
+ // because `mount` can be called after some preparation that can side effect unmount
403
+ // @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
404
+ setupHooks(preMountCleanup);
405
+
406
+ // mounting hooks inside a test component mostly copied from
407
+ // https://github.com/testing-library/react-hooks-testing-library/blob/master/src/pure.js
408
+ function resultContainer() {
409
+ var value = null;
410
+ var error = null;
411
+ var resolvers = [];
412
+ var result = {
413
+ get current() {
414
+ if (error) {
415
+ throw error;
416
+ }
417
+ return value;
418
+ },
419
+ get error() {
420
+ return error;
421
+ },
422
+ };
423
+ var updateResult = function (val, err) {
424
+ if (err === void 0) { err = null; }
425
+ value = val;
426
+ error = err;
427
+ resolvers.splice(0, resolvers.length).forEach(function (resolve) { return resolve(); });
428
+ };
429
+ return {
430
+ result: result,
431
+ addResolver: function (resolver) {
432
+ resolvers.push(resolver);
433
+ },
434
+ setValue: function (val) { return updateResult(val); },
435
+ setError: function (err) { return updateResult(undefined, err); },
436
+ };
437
+ }
438
+ function TestHook(_a) {
439
+ var callback = _a.callback, onError = _a.onError, children = _a.children;
440
+ try {
441
+ children(callback());
442
+ }
443
+ catch (err) {
444
+ if ('then' in err) {
445
+ throw err;
446
+ }
447
+ else {
448
+ onError(err);
449
+ }
450
+ }
451
+ return null;
452
+ }
453
+ /**
454
+ * Mounts a React hook function in a test component for testing.
455
+ *
456
+ */
457
+ var mountHook = function (hookFn) {
458
+ var _a = resultContainer(), result = _a.result, setValue = _a.setValue, setError = _a.setError;
459
+ var componentTest = React.createElement(TestHook, {
460
+ callback: hookFn,
461
+ onError: setError,
462
+ children: setValue,
463
+ });
464
+ return mount(componentTest).then(function () { return result; });
465
+ };
466
+
467
+ export { createMount, mount, mountHook, unmount };
@@ -0,0 +1,8 @@
1
+ import { JSX } from './mount';
2
+ /**
3
+ * Gets the display name of the component when possible.
4
+ * @param type {JSX} The type object returned from creating the react element.
5
+ * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
6
+ * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
7
+ */
8
+ export default function getDisplayName(type: JSX, fallbackName?: string): string;
@@ -0,0 +1,2 @@
1
+ export * from './mount';
2
+ export * from './mountHook';
@@ -0,0 +1,143 @@
1
+ /// <reference types="cypress" />
2
+ import * as React from 'react';
3
+ import * as ReactDOM from 'react-dom';
4
+ import { StyleOptions } from '@cypress/mount-utils';
5
+ /**
6
+ * Mount a React component in a blank document; register it as an alias
7
+ * To access: use an alias or original component reference
8
+ * @function mount
9
+ * @param {React.ReactElement} jsx - component to mount
10
+ * @param {MountOptions} [options] - options, like alias, styles
11
+ * @see https://github.com/bahmutov/@cypress/react
12
+ * @see https://glebbahmutov.com/blog/my-vision-for-component-tests/
13
+ * @example
14
+ ```
15
+ import Hello from './hello.jsx'
16
+ import { mount } from '@cypress/react'
17
+ it('works', () => {
18
+ mount(<Hello onClick={cy.stub()} />)
19
+ // use Cypress commands
20
+ cy.contains('Hello').click()
21
+ })
22
+ ```
23
+ **/
24
+ export declare const mount: (jsx: React.ReactNode, options?: MountOptions) => globalThis.Cypress.Chainable<MountReturn>;
25
+ /**
26
+ * Removes the mounted component. Notice this command automatically
27
+ * queues up the `unmount` into Cypress chain, thus you don't need `.then`
28
+ * to call it.
29
+ * @see https://github.com/cypress-io/cypress/tree/develop/npm/react/cypress/component/basic/unmount
30
+ * @example
31
+ ```
32
+ import { mount, unmount } from '@cypress/react'
33
+ it('works', () => {
34
+ mount(...)
35
+ // interact with the component using Cypress commands
36
+ // whenever you want to unmount
37
+ unmount()
38
+ })
39
+ ```
40
+ */
41
+ export declare const unmount: (options?: {
42
+ log: boolean;
43
+ }) => globalThis.Cypress.Chainable<JQuery<HTMLElement>>;
44
+ /**
45
+ * Creates new instance of `mount` function with default options
46
+ * @function createMount
47
+ * @param {MountOptions} [defaultOptions] - defaultOptions for returned `mount` function
48
+ * @returns new instance of `mount` with assigned options
49
+ * @example
50
+ * ```
51
+ * import Hello from './hello.jsx'
52
+ * import { createMount } from '@cypress/react'
53
+ *
54
+ * const mount = createMount({ strict: true, cssFile: 'path/to/any/css/file.css' })
55
+ *
56
+ * it('works', () => {
57
+ * mount(<Hello />)
58
+ * // use Cypress commands
59
+ * cy.get('button').should('have.css', 'color', 'rgb(124, 12, 109)')
60
+ * })
61
+ ```
62
+ **/
63
+ export declare const createMount: (defaultOptions: MountOptions) => (element: React.ReactElement, options?: Partial<StyleOptions & MountReactComponentOptions> | undefined) => globalThis.Cypress.Chainable<MountReturn>;
64
+ /** @deprecated Should be removed in the next major version */
65
+ export default mount;
66
+ export interface ReactModule {
67
+ name: string;
68
+ type: string;
69
+ location: string;
70
+ source: string;
71
+ }
72
+ export interface MountReactComponentOptions {
73
+ alias: string;
74
+ ReactDom: typeof ReactDOM;
75
+ /**
76
+ * Log the mounting command into Cypress Command Log,
77
+ * true by default.
78
+ */
79
+ log: boolean;
80
+ /**
81
+ * Render component in React [strict mode](https://reactjs.org/docs/strict-mode.html)
82
+ * It activates additional checks and warnings for child components.
83
+ */
84
+ strict: boolean;
85
+ }
86
+ export declare type MountOptions = Partial<StyleOptions & MountReactComponentOptions>;
87
+ export interface MountReturn {
88
+ /**
89
+ * The component that was rendered.
90
+ */
91
+ component: React.ReactNode;
92
+ /**
93
+ * Rerenders the specified component with new props. This allows testing of components that store state (`setState`)
94
+ * or have asynchronous updates (`useEffect`, `useLayoutEffect`).
95
+ */
96
+ rerender: (component: React.ReactNode) => globalThis.Cypress.Chainable<MountReturn>;
97
+ /**
98
+ * Removes the mounted component.
99
+ * @see `unmount`
100
+ */
101
+ unmount: () => globalThis.Cypress.Chainable<JQuery<HTMLElement>>;
102
+ }
103
+ /**
104
+ * The `type` property from the transpiled JSX object.
105
+ * @example
106
+ * const { type } = React.createElement('div', null, 'Hello')
107
+ * const { type } = <div>Hello</div>
108
+ */
109
+ export interface JSX extends Function {
110
+ displayName: string;
111
+ }
112
+ export declare namespace Cypress {
113
+ interface Cypress {
114
+ stylesCache: any;
115
+ React: string;
116
+ ReactDOM: string;
117
+ Styles: string;
118
+ modules: ReactModule[];
119
+ }
120
+ interface Chainable<Subject> {
121
+ state: (key: string) => any;
122
+ /**
123
+ * Mount a React component in a blank document; register it as an alias
124
+ * To access: use an alias or original component reference
125
+ * @function cy.mount
126
+ * @param {Object} jsx - component to mount
127
+ * @param {string} [Component] - alias to use later
128
+ * @example
129
+ ```
130
+ import Hello from './hello.jsx'
131
+ // mount and access by alias
132
+ cy.mount(<Hello />, 'Hello')
133
+ // using default alias
134
+ cy.get('@Component')
135
+ // using specified alias
136
+ cy.get('@Hello').its('state').should(...)
137
+ // using original component
138
+ cy.get(Hello)
139
+ ```
140
+ **/
141
+ get<S = any>(alias: string | symbol | Function, options?: Partial<any>): Chainable<any>;
142
+ }
143
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="cypress" />
2
+ declare type MountHookResult<T> = {
3
+ readonly current: T | null | undefined;
4
+ readonly error: Error | null;
5
+ };
6
+ /**
7
+ * Mounts a React hook function in a test component for testing.
8
+ *
9
+ */
10
+ export declare const mountHook: <T>(hookFn: (...args: any[]) => T) => Cypress.Chainable<MountHookResult<T>>;
11
+ export {};