cypress 15.7.1 → 15.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@cypress/angular-zoneless",
3
+ "version": "0.0.0-development",
4
+ "description": "Test Angular Components with Cypress without zone.js",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "prebuild": "rimraf dist",
8
+ "build": "rollup -c rollup.config.mjs",
9
+ "postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
10
+ "check-ts": "tsc --noEmit",
11
+ "dev": "rollup -c rollup.config.mjs -w",
12
+ "lint": "eslint --ext .js,.ts,.json, ."
13
+ },
14
+ "dependencies": {},
15
+ "devDependencies": {
16
+ "@angular/common": "^21.0.0",
17
+ "@angular/core": "^21.0.0",
18
+ "@angular/platform-browser-dynamic": "^21.0.0",
19
+ "@cypress/mount-utils": "0.0.0-development",
20
+ "rollup": "^4.24.4",
21
+ "typescript": "~5.9.2"
22
+ },
23
+ "peerDependencies": {
24
+ "@angular/common": ">=20.0.0",
25
+ "@angular/core": ">=20.0.0",
26
+ "@angular/platform-browser-dynamic": ">=20.0.0",
27
+ "rxjs": ">=7.8.0"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "types": "dist/index.d.ts",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/cypress-io/cypress.git"
37
+ },
38
+ "homepage": "https://github.com/cypress-io/cypress/blob/develop/npm/angular-zoneless/#readme",
39
+ "bugs": "https://github.com/cypress-io/cypress/issues/new?assignees=&labels=npm%3A%20%40cypress%2Fangular-zoneless&template=1-bug-report.md&title=",
40
+ "keywords": [
41
+ "angular",
42
+ "cypress",
43
+ "cypress-io",
44
+ "test",
45
+ "testing",
46
+ "zoneless"
47
+ ],
48
+ "contributors": [
49
+ {
50
+ "name": "Bill Glesias",
51
+ "social": "@atofstryker"
52
+ }
53
+ ],
54
+ "module": "dist/index.js",
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "nx": {
59
+ "targets": {
60
+ "build": {
61
+ "outputs": [
62
+ "{workspaceRoot}/cli/angular-zoneless"
63
+ ]
64
+ }
65
+ }
66
+ },
67
+ "standard": {
68
+ "globals": [
69
+ "Cypress",
70
+ "cy",
71
+ "expect"
72
+ ]
73
+ }
74
+ }
@@ -0,0 +1,119 @@
1
+ /// <reference types="cypress" />
2
+
3
+ import { InputSignal, WritableSignal, Type } from '@angular/core';
4
+ import { TestModuleMetadata, ComponentFixture, TestComponentRenderer } from '@angular/core/testing';
5
+
6
+ /**
7
+ * Additional module configurations needed while mounting the component, like
8
+ * providers, declarations, imports and even component @Inputs()
9
+ *
10
+ * @interface MountConfig
11
+ * @see https://angular.io/api/core/testing/TestModuleMetadata
12
+ */
13
+ interface MountConfig<T> extends TestModuleMetadata {
14
+ /**
15
+ * @memberof MountConfig
16
+ * @example
17
+ * import { ButtonComponent } from 'button/button.component'
18
+ * it('renders a button with Save text', () => {
19
+ * cy.mount(ButtonComponent, { componentProperties: { text: 'Save' }})
20
+ * cy.get('button').contains('Save')
21
+ * })
22
+ *
23
+ * it('renders a button with a cy.spy() replacing EventEmitter', () => {
24
+ * cy.mount(ButtonComponent, {
25
+ * componentProperties: {
26
+ * clicked: cy.spy().as('mySpy)
27
+ * }
28
+ * })
29
+ * cy.get('button').click()
30
+ * cy.get('@mySpy').should('have.been.called')
31
+ * })
32
+ */
33
+ componentProperties?: Partial<{
34
+ [P in keyof T]: T[P] extends InputSignal<infer V> ? InputSignal<V> | WritableSignal<V> | V : T[P];
35
+ }>;
36
+ }
37
+ /**
38
+ * Type that the `mount` function returns
39
+ * @type MountResponse<T>
40
+ */
41
+ type MountResponse<T> = {
42
+ /**
43
+ * Fixture for debugging and testing a component.
44
+ *
45
+ * @memberof MountResponse
46
+ * @see https://angular.io/api/core/testing/ComponentFixture
47
+ */
48
+ fixture: ComponentFixture<T>;
49
+ /**
50
+ * The instance of the root component class
51
+ *
52
+ * @memberof MountResponse
53
+ * @see https://angular.io/api/core/testing/ComponentFixture#componentInstance
54
+ */
55
+ component: T;
56
+ };
57
+ declare class CypressTestComponentRenderer extends TestComponentRenderer {
58
+ insertRootElement(rootElId: string): void;
59
+ removeAllRootElements(): void;
60
+ }
61
+ /**
62
+ * Mounts an Angular component inside Cypress browser
63
+ *
64
+ * @param component Angular component being mounted or its template
65
+ * @param config configuration used to configure the TestBed
66
+ * @example
67
+ * import { mount } from '@cypress/angular'
68
+ * import { StepperComponent } from './stepper.component'
69
+ * import { MyService } from 'services/my.service'
70
+ * import { SharedModule } from 'shared/shared.module';
71
+ * it('mounts', () => {
72
+ * mount(StepperComponent, {
73
+ * providers: [MyService],
74
+ * imports: [SharedModule]
75
+ * })
76
+ * cy.get('[data-cy=increment]').click()
77
+ * cy.get('[data-cy=counter]').should('have.text', '1')
78
+ * })
79
+ *
80
+ * // or
81
+ *
82
+ * it('mounts with template', () => {
83
+ * mount('<app-stepper></app-stepper>', {
84
+ * declarations: [StepperComponent],
85
+ * })
86
+ * })
87
+ *
88
+ * @see {@link https://on.cypress.io/mounting-angular} for more details.
89
+ *
90
+ * @returns A component and component fixture
91
+ */
92
+ declare function mount<T>(component: Type<T> | string, config?: MountConfig<T>): Cypress.Chainable<MountResponse<T>>;
93
+ /**
94
+ * Creates a new Event Emitter and then spies on it's `emit` method
95
+ *
96
+ * @param {string} alias name you want to use for your cy.spy() alias
97
+ * @returns EventEmitter<T>
98
+ * @example
99
+ * import { StepperComponent } from './stepper.component'
100
+ * import { mount, createOutputSpy } from '@cypress/angular'
101
+ *
102
+ * it('Has spy', () => {
103
+ * mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
104
+ * cy.get('[data-cy=increment]').click()
105
+ * cy.get('@changeSpy').should('have.been.called')
106
+ * })
107
+ *
108
+ * // Or for use with Angular Signals following the output nomenclature.
109
+ * // see https://v17.angular.io/guide/model-inputs#differences-between-model-and-input/
110
+ *
111
+ * it('Has spy', () => {
112
+ * mount(StepperComponent, { componentProperties: { count: signal(0), countChange: createOutputSpy('countChange') } })
113
+ * cy.get('[data-cy=increment]').click()
114
+ * cy.get('@countChange').should('have.been.called')
115
+ * })
116
+ */
117
+ declare const createOutputSpy: <T>(alias: string) => any;
118
+
119
+ export { CypressTestComponentRenderer, MountConfig, MountResponse, createOutputSpy, mount };
@@ -0,0 +1,482 @@
1
+
2
+ /**
3
+ * @cypress/angular-zoneless v0.0.0-development
4
+ * (c) 2025 Cypress.io
5
+ * Released under the MIT License
6
+ */
7
+
8
+ import { CommonModule } from '@angular/common';
9
+ import { Injectable, Component, EventEmitter, ErrorHandler, provideZonelessChangeDetection, SimpleChange } from '@angular/core';
10
+ import { toObservable } from '@angular/core/rxjs-interop';
11
+ import { getTestBed, TestComponentRenderer, TestBed } from '@angular/core/testing';
12
+ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
13
+
14
+ /******************************************************************************
15
+ Copyright (c) Microsoft Corporation.
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
+ PERFORMANCE OF THIS SOFTWARE.
27
+ ***************************************************************************** */
28
+ /* global Reflect, Promise, SuppressedError, Symbol */
29
+
30
+
31
+ function __rest(s, e) {
32
+ var t = {};
33
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
34
+ t[p] = s[p];
35
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
36
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
+ t[p[i]] = s[p[i]];
39
+ }
40
+ return t;
41
+ }
42
+
43
+ function __decorate(decorators, target, key, desc) {
44
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
45
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
46
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
48
+ }
49
+
50
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
51
+ var e = new Error(message);
52
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
+ };
54
+
55
+ const ROOT_SELECTOR = '[data-cy-root]';
56
+ /**
57
+ * Gets the root element used to mount the component.
58
+ * @returns {HTMLElement} The root element
59
+ * @throws {Error} If the root element is not found
60
+ */
61
+ const getContainerEl = () => {
62
+ const el = document.querySelector(ROOT_SELECTOR);
63
+ if (el) {
64
+ return el;
65
+ }
66
+ throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please add a root element with data-cy-root attribute to your "component-index.html" file so that Cypress can attach your component to the DOM.`);
67
+ };
68
+ /**
69
+ * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
70
+ * @param optionalCallback Callback to be called before the next test runs
71
+ */
72
+ function setupHooks(optionalCallback) {
73
+ // We don't want CT side effects to run when e2e
74
+ // testing so we early return.
75
+ // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
76
+ if (Cypress.testingType !== 'component') {
77
+ return;
78
+ }
79
+ // When running component specs, we cannot allow "cy.visit"
80
+ // because it will wipe out our preparation work, and does not make much sense
81
+ // thus we overwrite "cy.visit" to throw an error
82
+ Cypress.Commands.overwrite('visit', () => {
83
+ throw new Error('cy.visit from a component spec is not allowed');
84
+ });
85
+ Cypress.Commands.overwrite('session', () => {
86
+ throw new Error('cy.session from a component spec is not allowed');
87
+ });
88
+ Cypress.Commands.overwrite('origin', () => {
89
+ throw new Error('cy.origin from a component spec is not allowed');
90
+ });
91
+ // @ts-ignore
92
+ Cypress.on('test:before:after:run:async', () => {
93
+ optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
94
+ });
95
+ }
96
+
97
+ let activeFixture = null;
98
+ let activeInternalSubscriptions = [];
99
+ function cleanup() {
100
+ // Not public, we need to call this to remove the last component from the DOM
101
+ try {
102
+ getTestBed().tearDownTestingModule();
103
+ }
104
+ catch (e) {
105
+ const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`);
106
+ notSupportedError.docsUrl = 'https://on.cypress.io/frameworks';
107
+ throw notSupportedError;
108
+ }
109
+ // clean up internal subscriptions if any exist. We use this for two-way data binding for
110
+ // signal() models
111
+ activeInternalSubscriptions.forEach((subscription) => {
112
+ subscription.unsubscribe();
113
+ });
114
+ getTestBed().resetTestingModule();
115
+ activeFixture = null;
116
+ activeInternalSubscriptions = [];
117
+ }
118
+ let CypressAngularErrorHandler = class CypressAngularErrorHandler {
119
+ handleError(error) {
120
+ throw error;
121
+ }
122
+ };
123
+ CypressAngularErrorHandler = __decorate([
124
+ Injectable()
125
+ ], CypressAngularErrorHandler);
126
+ /**
127
+ * Bootstraps the TestModuleMetaData passed to the TestBed
128
+ *
129
+ * @param {Type<T>} component Angular component being mounted
130
+ * @param {MountConfig} config TestBed configuration passed into the mount function
131
+ * @returns {MountConfig} MountConfig
132
+ */
133
+ function bootstrapModule(component, config) {
134
+ var _a;
135
+ const { componentProperties } = config, testModuleMetaData = __rest(config, ["componentProperties"]);
136
+ if (!testModuleMetaData.declarations) {
137
+ testModuleMetaData.declarations = [];
138
+ }
139
+ if (!testModuleMetaData.imports) {
140
+ testModuleMetaData.imports = [];
141
+ }
142
+ if (!testModuleMetaData.providers) {
143
+ testModuleMetaData.providers = [];
144
+ }
145
+ // Replace default error handler since it will swallow uncaught exceptions.
146
+ // We want these to be uncaught so Cypress catches it and fails the test
147
+ testModuleMetaData.providers.push({
148
+ provide: ErrorHandler,
149
+ useClass: CypressAngularErrorHandler,
150
+ });
151
+ // allow for zoneless change detection inside the testing module.
152
+ // @see https://angular.dev/guide/zoneless#using-zoneless-in-testbed
153
+ testModuleMetaData.providers.push(provideZonelessChangeDetection());
154
+ // check if the component is a standalone component
155
+ if ((_a = component.ɵcmp) === null || _a === void 0 ? void 0 : _a.standalone) {
156
+ testModuleMetaData.imports.push(component);
157
+ }
158
+ else {
159
+ testModuleMetaData.declarations.push(component);
160
+ }
161
+ if (!testModuleMetaData.imports.includes(CommonModule)) {
162
+ testModuleMetaData.imports.push(CommonModule);
163
+ }
164
+ return testModuleMetaData;
165
+ }
166
+ let CypressTestComponentRenderer = class CypressTestComponentRenderer extends TestComponentRenderer {
167
+ insertRootElement(rootElId) {
168
+ this.removeAllRootElements();
169
+ const rootElement = getContainerEl();
170
+ rootElement.setAttribute('id', rootElId);
171
+ }
172
+ removeAllRootElements() {
173
+ getContainerEl().innerHTML = '';
174
+ }
175
+ };
176
+ CypressTestComponentRenderer = __decorate([
177
+ Injectable()
178
+ ], CypressTestComponentRenderer);
179
+ /**
180
+ * Initializes the TestBed
181
+ *
182
+ * @param {Type<T> | string} component Angular component being mounted or its template
183
+ * @param {MountConfig} config TestBed configuration passed into the mount function
184
+ * @returns {Type<T>} componentFixture
185
+ */
186
+ function initTestBed(component, config) {
187
+ const componentFixture = createComponentFixture(component);
188
+ getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, config)));
189
+ getTestBed().overrideProvider(TestComponentRenderer, { useValue: new CypressTestComponentRenderer() });
190
+ return componentFixture;
191
+ }
192
+ // if using the Wrapper Component (template strings), the component itself cannot be
193
+ // a standalone component
194
+ let WrapperComponent = class WrapperComponent {
195
+ };
196
+ WrapperComponent = __decorate([
197
+ Component({ selector: 'cy-wrapper-component', template: '', standalone: false })
198
+ ], WrapperComponent);
199
+ /**
200
+ * Returns the Component if Type<T> or creates a WrapperComponent
201
+ *
202
+ * @param {Type<T> | string} component The component you want to create a fixture of
203
+ * @returns {Type<T> | WrapperComponent}
204
+ */
205
+ function createComponentFixture(component) {
206
+ if (typeof component === 'string') {
207
+ // getTestBed().overrideTemplate is available in v14+
208
+ // The static TestBed.overrideTemplate is available across versions
209
+ TestBed.overrideTemplate(WrapperComponent, component);
210
+ return WrapperComponent;
211
+ }
212
+ return component;
213
+ }
214
+ /**
215
+ * Creates the ComponentFixture
216
+ *
217
+ * @param {Type<T>} component Angular component being mounted
218
+ * @param {MountConfig<T>} config MountConfig
219
+
220
+ * @returns {Promise<ComponentFixture<T>>} ComponentFixture
221
+ */
222
+ function setupFixture(component, config) {
223
+ const fixture = getTestBed().createComponent(component);
224
+ setupComponent(config, fixture);
225
+ return fixture;
226
+ }
227
+ // Best known way to currently detect whether or not a function is a signal is if the signal symbol exists.
228
+ // From there, we can take our best guess based on what exists on the object itself.
229
+ // @see https://github.com/cypress-io/cypress/issues/29731.
230
+ function isSignal(prop) {
231
+ try {
232
+ const symbol = Object.getOwnPropertySymbols(prop).find((symbol) => symbol.toString() === 'Symbol(SIGNAL)');
233
+ return !!symbol;
234
+ }
235
+ catch (e) {
236
+ // likely a primitive type, object, array, or something else (i.e. not a signal).
237
+ // We can return false here.
238
+ return false;
239
+ }
240
+ }
241
+ // currently not a great way to detect if a function is an InputSignal.
242
+ // @see https://github.com/cypress-io/cypress/issues/29731.
243
+ function isInputSignal(prop) {
244
+ return isSignal(prop) && typeof prop === 'function' && prop['name'] === 'inputValueFn';
245
+ }
246
+ // currently not a great way to detect if a function is a Model Signal.
247
+ // @see https://github.com/cypress-io/cypress/issues/29731.
248
+ function isModelSignal(prop) {
249
+ return isSignal(prop) && isWritableSignal(prop) && typeof prop.subscribe === 'function';
250
+ }
251
+ // currently not a great way to detect if a function is a Writable Signal.
252
+ // @see https://github.com/cypress-io/cypress/issues/29731.
253
+ function isWritableSignal(prop) {
254
+ return isSignal(prop) && typeof prop === 'function' && typeof prop.set === 'function';
255
+ }
256
+ function registerSignalEventsIfNeeded(propKey, propValue, componentValue, injector, fixture) {
257
+ const isPropValueASignal = isSignal(propValue);
258
+ if (isPropValueASignal) {
259
+ // propValue -> componentValue
260
+ const convertedToObservable = toObservable(propValue, {
261
+ // @ts-expect-error - monorepo clashing types between Angular 18 and Angular 21
262
+ injector,
263
+ });
264
+ // push the subscription into an array to be cleaned up at the end of the test
265
+ // to prevent a memory leak
266
+ activeInternalSubscriptions.push(convertedToObservable.subscribe((value) => {
267
+ // keep the component up to date as prop signal changes
268
+ fixture.componentRef.setInput(propKey, value);
269
+ }));
270
+ }
271
+ const isComponentValueAModelSignal = isModelSignal(componentValue);
272
+ if (isPropValueASignal && isComponentValueAModelSignal) {
273
+ // propValue <- componentValue
274
+ const modelChanged$ = toObservable(componentValue, {
275
+ // @ts-expect-error - monorepo clashing types between Angular 18 and Angular 21
276
+ injector,
277
+ });
278
+ activeInternalSubscriptions.push(modelChanged$.subscribe((value) => {
279
+ propValue.set(value);
280
+ }));
281
+ }
282
+ }
283
+ // In the case of signals, if we need to create an output spy, we need to check first whether or not a user has one defined first or has it created through
284
+ // autoSpyOutputs. If so, we need to subscribe to the writable signal to push updates into the event emitter. We do NOT observe input signals and output spies will not
285
+ // work for input signals.
286
+ function detectAndRegisterOutputSpyToSignal(config, component, key, injector) {
287
+ if (config.componentProperties) {
288
+ const expectedChangeKey = `${key}Change`;
289
+ let changeKeyIfExists = !!Object.keys(config.componentProperties).find((componentKey) => componentKey === expectedChangeKey);
290
+ if (changeKeyIfExists) {
291
+ component[expectedChangeKey] =
292
+ // @ts-expect-error
293
+ config.componentProperties[expectedChangeKey];
294
+ }
295
+ if (changeKeyIfExists) {
296
+ const componentValue = component[key];
297
+ // if the user passed in a change key or we created one due to config.autoSpyOutputs being set to true for a given signal,
298
+ // we will create a subscriber that will emit an event every time the value inside the signal changes. We only do this
299
+ // if the signal is writable and not an input signal.
300
+ if (isWritableSignal(componentValue) && !isInputSignal(componentValue)) {
301
+ activeInternalSubscriptions.push(toObservable(componentValue, {
302
+ // @ts-expect-error - monorepo clashing types between Angular 18 and Angular 21
303
+ injector,
304
+ }).subscribe((value) => {
305
+ var _a;
306
+ (_a = component[expectedChangeKey]) === null || _a === void 0 ? void 0 : _a.emit(value);
307
+ }));
308
+ }
309
+ }
310
+ }
311
+ }
312
+ /**
313
+ * Gets the componentInstance and Object.assigns any componentProperties() passed in the MountConfig
314
+ *
315
+ * @param {MountConfig} config TestBed configuration passed into the mount function
316
+ * @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
317
+ * @returns {T} Component being mounted
318
+ */
319
+ function setupComponent(config, fixture) {
320
+ let component = fixture.componentInstance;
321
+ const injector = fixture.componentRef.injector;
322
+ if (config === null || config === void 0 ? void 0 : config.componentProperties) {
323
+ if (component instanceof WrapperComponent) {
324
+ component = Object.assign(component, config.componentProperties);
325
+ }
326
+ getComponentInputs(fixture.componentRef.componentType).forEach((key) => {
327
+ var _a;
328
+ // only assign props if they are passed into the component
329
+ if ((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) {
330
+ // @ts-expect-error
331
+ const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
332
+ registerSignalEventsIfNeeded(key, passedInValue, component[key], injector, fixture);
333
+ detectAndRegisterOutputSpyToSignal(config, component, key, injector);
334
+ fixture.componentRef.setInput(key, isSignal(passedInValue) ? passedInValue() : passedInValue);
335
+ }
336
+ });
337
+ getComponentOutputs(fixture.componentRef.componentType).forEach((key) => {
338
+ var _a, _b;
339
+ const property = component[key];
340
+ // With the introduction of https://github.com/cypress-io/cypress/pull/31993, we want to make sure that component inputs are reference safe inside cy.mount().
341
+ // However, the exception to this is if the user passes in a Cypress output spy as a property in order to maintain backwards compatibility.
342
+ // @ts-expect-error
343
+ if (property instanceof EventEmitter || (((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) && (config === null || config === void 0 ? void 0 : config.componentProperties[key]) instanceof EventEmitter)) {
344
+ // only assign props if they are passed into the component
345
+ if ((_b = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _b === void 0 ? void 0 : _b.hasOwnProperty(key)) {
346
+ // @ts-expect-error
347
+ const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
348
+ component[key] = passedInValue;
349
+ }
350
+ }
351
+ });
352
+ }
353
+ // Manually call ngOnChanges when mounting components using the class syntax.
354
+ // This is necessary because we are assigning input values to the class directly
355
+ // on mount and therefore the ngOnChanges() lifecycle is not triggered.
356
+ if (component.ngOnChanges && config.componentProperties) {
357
+ const { componentProperties } = config;
358
+ const simpleChanges = Object.entries(componentProperties).reduce((acc, [key, value]) => {
359
+ acc[key] = new SimpleChange(null, value, true);
360
+ return acc;
361
+ }, {});
362
+ if (Object.keys(componentProperties).length > 0) {
363
+ component.ngOnChanges(simpleChanges);
364
+ }
365
+ }
366
+ }
367
+ /**
368
+ * Gets the input properties of a component - cannot rely on Object.keys() because inclusion of optional properties depends on useDefineForClassFields=true
369
+ * Since Angular 15, useDefineForClassFields=false
370
+ * @param componentType
371
+ * @returns array of input property names
372
+ */
373
+ function getComponentInputs(componentType) {
374
+ var _a;
375
+ // Access Angular's metadata to get input properties
376
+ const propMetadata = ((_a = componentType.ɵcmp) === null || _a === void 0 ? void 0 : _a.inputs) || {};
377
+ return Object.keys(propMetadata);
378
+ }
379
+ function getComponentOutputs(componentType) {
380
+ var _a;
381
+ // Access Angular's metadata to get output properties
382
+ const propMetadata = ((_a = componentType.ɵcmp) === null || _a === void 0 ? void 0 : _a.outputs) || {};
383
+ return Object.keys(propMetadata);
384
+ }
385
+ /**
386
+ * Mounts an Angular component inside Cypress browser
387
+ *
388
+ * @param component Angular component being mounted or its template
389
+ * @param config configuration used to configure the TestBed
390
+ * @example
391
+ * import { mount } from '@cypress/angular'
392
+ * import { StepperComponent } from './stepper.component'
393
+ * import { MyService } from 'services/my.service'
394
+ * import { SharedModule } from 'shared/shared.module';
395
+ * it('mounts', () => {
396
+ * mount(StepperComponent, {
397
+ * providers: [MyService],
398
+ * imports: [SharedModule]
399
+ * })
400
+ * cy.get('[data-cy=increment]').click()
401
+ * cy.get('[data-cy=counter]').should('have.text', '1')
402
+ * })
403
+ *
404
+ * // or
405
+ *
406
+ * it('mounts with template', () => {
407
+ * mount('<app-stepper></app-stepper>', {
408
+ * declarations: [StepperComponent],
409
+ * })
410
+ * })
411
+ *
412
+ * @see {@link https://on.cypress.io/mounting-angular} for more details.
413
+ *
414
+ * @returns A component and component fixture
415
+ */
416
+ function mount(component, config = {}) {
417
+ // Remove last mounted component if cy.mount is called more than once in a test
418
+ if (activeFixture) {
419
+ cleanup();
420
+ }
421
+ const componentFixture = initTestBed(component, config);
422
+ let mountResponsePromiseResolver;
423
+ let mountResponsePromiseRejector;
424
+ let mountResponsePromise = new Promise((resolve, reject) => {
425
+ mountResponsePromiseResolver = resolve;
426
+ mountResponsePromiseRejector = reject;
427
+ });
428
+ const fixture = setupFixture(componentFixture, config);
429
+ activeFixture = fixture;
430
+ fixture.whenStable().then(() => {
431
+ const mountResponse = {
432
+ fixture,
433
+ component: fixture.componentInstance,
434
+ };
435
+ const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name;
436
+ Cypress.log({
437
+ name: 'mount',
438
+ message: logMessage,
439
+ consoleProps: () => ({ result: mountResponse }),
440
+ });
441
+ mountResponsePromiseResolver(mountResponse);
442
+ }).catch((error) => {
443
+ mountResponsePromiseRejector(error);
444
+ });
445
+ return cy.wrap(mountResponsePromise, { log: false });
446
+ }
447
+ /**
448
+ * Creates a new Event Emitter and then spies on it's `emit` method
449
+ *
450
+ * @param {string} alias name you want to use for your cy.spy() alias
451
+ * @returns EventEmitter<T>
452
+ * @example
453
+ * import { StepperComponent } from './stepper.component'
454
+ * import { mount, createOutputSpy } from '@cypress/angular'
455
+ *
456
+ * it('Has spy', () => {
457
+ * mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
458
+ * cy.get('[data-cy=increment]').click()
459
+ * cy.get('@changeSpy').should('have.been.called')
460
+ * })
461
+ *
462
+ * // Or for use with Angular Signals following the output nomenclature.
463
+ * // see https://v17.angular.io/guide/model-inputs#differences-between-model-and-input/
464
+ *
465
+ * it('Has spy', () => {
466
+ * mount(StepperComponent, { componentProperties: { count: signal(0), countChange: createOutputSpy('countChange') } })
467
+ * cy.get('[data-cy=increment]').click()
468
+ * cy.get('@countChange').should('have.been.called')
469
+ * })
470
+ */
471
+ const createOutputSpy = (alias) => {
472
+ const emitter = new EventEmitter();
473
+ cy.spy(emitter, 'emit').as(alias);
474
+ return emitter;
475
+ };
476
+ // Only needs to run once, we reset before each test
477
+ getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
478
+ teardown: { destroyAfterEach: false },
479
+ });
480
+ setupHooks(cleanup);
481
+
482
+ export { CypressTestComponentRenderer, createOutputSpy, mount };