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
@@ -56,7 +56,7 @@ interface MountConfig<T> extends TestModuleMetadata {
|
|
56
56
|
* Type that the `mount` function returns
|
57
57
|
* @type MountResponse<T>
|
58
58
|
*/
|
59
|
-
|
59
|
+
type MountResponse<T> = {
|
60
60
|
/**
|
61
61
|
* Fixture for debugging and testing a component.
|
62
62
|
*
|
@@ -95,246 +95,246 @@ function setupHooks(optionalCallback) {
|
|
95
95
|
});
|
96
96
|
}
|
97
97
|
|
98
|
-
/**
|
99
|
-
* @hack fixes "Mocha has already been patched with Zone" error.
|
100
|
-
*/
|
101
|
-
// @ts-ignore
|
102
|
-
window.Mocha['__zone_patch__'] = false;
|
103
|
-
let activeFixture = null;
|
104
|
-
function cleanup() {
|
105
|
-
// Not public, we need to call this to remove the last component from the DOM
|
106
|
-
try {
|
107
|
-
getTestBed().tearDownTestingModule();
|
108
|
-
}
|
109
|
-
catch (e) {
|
110
|
-
const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`);
|
111
|
-
notSupportedError.docsUrl = 'https://on.cypress.io/component-framework-configuration';
|
112
|
-
throw notSupportedError;
|
113
|
-
}
|
114
|
-
getTestBed().resetTestingModule();
|
115
|
-
activeFixture = null;
|
116
|
-
}
|
117
|
-
// 'zone.js/testing' is not properly aliasing `it.skip` but it does provide `xit`/`xspecify`
|
118
|
-
// Written up under https://github.com/angular/angular/issues/46297 but is not seeing movement
|
119
|
-
// so we'll patch here pending a fix in that library
|
120
|
-
// @ts-ignore Ignore so that way we can bypass semantic error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
|
121
|
-
globalThis.it.skip = globalThis.xit;
|
122
|
-
let CypressAngularErrorHandler = class CypressAngularErrorHandler {
|
123
|
-
handleError(error) {
|
124
|
-
throw error;
|
125
|
-
}
|
126
|
-
};
|
127
|
-
CypressAngularErrorHandler = __decorate([
|
128
|
-
Injectable()
|
129
|
-
], CypressAngularErrorHandler);
|
130
|
-
/**
|
131
|
-
* Bootstraps the TestModuleMetaData passed to the TestBed
|
132
|
-
*
|
133
|
-
* @param {Type<T>} component Angular component being mounted
|
134
|
-
* @param {MountConfig} config TestBed configuration passed into the mount function
|
135
|
-
* @returns {MountConfig} MountConfig
|
136
|
-
*/
|
137
|
-
function bootstrapModule(component, config) {
|
138
|
-
var _a;
|
139
|
-
const testModuleMetaData = __rest(config, ["componentProperties"]);
|
140
|
-
if (!testModuleMetaData.declarations) {
|
141
|
-
testModuleMetaData.declarations = [];
|
142
|
-
}
|
143
|
-
if (!testModuleMetaData.imports) {
|
144
|
-
testModuleMetaData.imports = [];
|
145
|
-
}
|
146
|
-
if (!testModuleMetaData.providers) {
|
147
|
-
testModuleMetaData.providers = [];
|
148
|
-
}
|
149
|
-
// Replace default error handler since it will swallow uncaught exceptions.
|
150
|
-
// We want these to be uncaught so Cypress catches it and fails the test
|
151
|
-
testModuleMetaData.providers.push({
|
152
|
-
provide: ErrorHandler,
|
153
|
-
useClass: CypressAngularErrorHandler,
|
154
|
-
});
|
155
|
-
// check if the component is a standalone component
|
156
|
-
if ((_a = component.ɵcmp) === null || _a === void 0 ? void 0 : _a.standalone) {
|
157
|
-
testModuleMetaData.imports.push(component);
|
158
|
-
}
|
159
|
-
else {
|
160
|
-
testModuleMetaData.declarations.push(component);
|
161
|
-
}
|
162
|
-
if (!testModuleMetaData.imports.includes(CommonModule)) {
|
163
|
-
testModuleMetaData.imports.push(CommonModule);
|
164
|
-
}
|
165
|
-
return testModuleMetaData;
|
166
|
-
}
|
167
|
-
let CypressTestComponentRenderer = class CypressTestComponentRenderer extends TestComponentRenderer {
|
168
|
-
insertRootElement(rootElId) {
|
169
|
-
this.removeAllRootElements();
|
170
|
-
const rootElement = getContainerEl();
|
171
|
-
rootElement.setAttribute('id', rootElId);
|
172
|
-
}
|
173
|
-
removeAllRootElements() {
|
174
|
-
getContainerEl().innerHTML = '';
|
175
|
-
}
|
176
|
-
};
|
177
|
-
CypressTestComponentRenderer = __decorate([
|
178
|
-
Injectable()
|
179
|
-
], CypressTestComponentRenderer);
|
180
|
-
/**
|
181
|
-
* Initializes the TestBed
|
182
|
-
*
|
183
|
-
* @param {Type<T> | string} component Angular component being mounted or its template
|
184
|
-
* @param {MountConfig} config TestBed configuration passed into the mount function
|
185
|
-
* @returns {Type<T>} componentFixture
|
186
|
-
*/
|
187
|
-
function initTestBed(component, config) {
|
188
|
-
const componentFixture = createComponentFixture(component);
|
189
|
-
getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, config)));
|
190
|
-
getTestBed().overrideProvider(TestComponentRenderer, { useValue: new CypressTestComponentRenderer() });
|
191
|
-
return componentFixture;
|
192
|
-
}
|
193
|
-
let WrapperComponent = class WrapperComponent {
|
194
|
-
};
|
195
|
-
WrapperComponent = __decorate([
|
196
|
-
Component({ selector: 'cy-wrapper-component', template: '' })
|
197
|
-
], WrapperComponent);
|
198
|
-
/**
|
199
|
-
* Returns the Component if Type<T> or creates a WrapperComponent
|
200
|
-
*
|
201
|
-
* @param {Type<T> | string} component The component you want to create a fixture of
|
202
|
-
* @returns {Type<T> | WrapperComponent}
|
203
|
-
*/
|
204
|
-
function createComponentFixture(component) {
|
205
|
-
if (typeof component === 'string') {
|
206
|
-
// getTestBed().overrideTemplate is available in v14+
|
207
|
-
// The static TestBed.overrideTemplate is available across versions
|
208
|
-
TestBed.overrideTemplate(WrapperComponent, component);
|
209
|
-
return WrapperComponent;
|
210
|
-
}
|
211
|
-
return component;
|
212
|
-
}
|
213
|
-
/**
|
214
|
-
* Creates the ComponentFixture
|
215
|
-
*
|
216
|
-
* @param {Type<T>} component Angular component being mounted
|
217
|
-
* @param {MountConfig<T>} config MountConfig
|
98
|
+
/**
|
99
|
+
* @hack fixes "Mocha has already been patched with Zone" error.
|
100
|
+
*/
|
101
|
+
// @ts-ignore
|
102
|
+
window.Mocha['__zone_patch__'] = false;
|
103
|
+
let activeFixture = null;
|
104
|
+
function cleanup() {
|
105
|
+
// Not public, we need to call this to remove the last component from the DOM
|
106
|
+
try {
|
107
|
+
getTestBed().tearDownTestingModule();
|
108
|
+
}
|
109
|
+
catch (e) {
|
110
|
+
const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`);
|
111
|
+
notSupportedError.docsUrl = 'https://on.cypress.io/component-framework-configuration';
|
112
|
+
throw notSupportedError;
|
113
|
+
}
|
114
|
+
getTestBed().resetTestingModule();
|
115
|
+
activeFixture = null;
|
116
|
+
}
|
117
|
+
// 'zone.js/testing' is not properly aliasing `it.skip` but it does provide `xit`/`xspecify`
|
118
|
+
// Written up under https://github.com/angular/angular/issues/46297 but is not seeing movement
|
119
|
+
// so we'll patch here pending a fix in that library
|
120
|
+
// @ts-ignore Ignore so that way we can bypass semantic error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
|
121
|
+
globalThis.it.skip = globalThis.xit;
|
122
|
+
let CypressAngularErrorHandler = class CypressAngularErrorHandler {
|
123
|
+
handleError(error) {
|
124
|
+
throw error;
|
125
|
+
}
|
126
|
+
};
|
127
|
+
CypressAngularErrorHandler = __decorate([
|
128
|
+
Injectable()
|
129
|
+
], CypressAngularErrorHandler);
|
130
|
+
/**
|
131
|
+
* Bootstraps the TestModuleMetaData passed to the TestBed
|
132
|
+
*
|
133
|
+
* @param {Type<T>} component Angular component being mounted
|
134
|
+
* @param {MountConfig} config TestBed configuration passed into the mount function
|
135
|
+
* @returns {MountConfig} MountConfig
|
136
|
+
*/
|
137
|
+
function bootstrapModule(component, config) {
|
138
|
+
var _a;
|
139
|
+
const testModuleMetaData = __rest(config, ["componentProperties"]);
|
140
|
+
if (!testModuleMetaData.declarations) {
|
141
|
+
testModuleMetaData.declarations = [];
|
142
|
+
}
|
143
|
+
if (!testModuleMetaData.imports) {
|
144
|
+
testModuleMetaData.imports = [];
|
145
|
+
}
|
146
|
+
if (!testModuleMetaData.providers) {
|
147
|
+
testModuleMetaData.providers = [];
|
148
|
+
}
|
149
|
+
// Replace default error handler since it will swallow uncaught exceptions.
|
150
|
+
// We want these to be uncaught so Cypress catches it and fails the test
|
151
|
+
testModuleMetaData.providers.push({
|
152
|
+
provide: ErrorHandler,
|
153
|
+
useClass: CypressAngularErrorHandler,
|
154
|
+
});
|
155
|
+
// check if the component is a standalone component
|
156
|
+
if ((_a = component.ɵcmp) === null || _a === void 0 ? void 0 : _a.standalone) {
|
157
|
+
testModuleMetaData.imports.push(component);
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
testModuleMetaData.declarations.push(component);
|
161
|
+
}
|
162
|
+
if (!testModuleMetaData.imports.includes(CommonModule)) {
|
163
|
+
testModuleMetaData.imports.push(CommonModule);
|
164
|
+
}
|
165
|
+
return testModuleMetaData;
|
166
|
+
}
|
167
|
+
let CypressTestComponentRenderer = class CypressTestComponentRenderer extends TestComponentRenderer {
|
168
|
+
insertRootElement(rootElId) {
|
169
|
+
this.removeAllRootElements();
|
170
|
+
const rootElement = getContainerEl();
|
171
|
+
rootElement.setAttribute('id', rootElId);
|
172
|
+
}
|
173
|
+
removeAllRootElements() {
|
174
|
+
getContainerEl().innerHTML = '';
|
175
|
+
}
|
176
|
+
};
|
177
|
+
CypressTestComponentRenderer = __decorate([
|
178
|
+
Injectable()
|
179
|
+
], CypressTestComponentRenderer);
|
180
|
+
/**
|
181
|
+
* Initializes the TestBed
|
182
|
+
*
|
183
|
+
* @param {Type<T> | string} component Angular component being mounted or its template
|
184
|
+
* @param {MountConfig} config TestBed configuration passed into the mount function
|
185
|
+
* @returns {Type<T>} componentFixture
|
186
|
+
*/
|
187
|
+
function initTestBed(component, config) {
|
188
|
+
const componentFixture = createComponentFixture(component);
|
189
|
+
getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, config)));
|
190
|
+
getTestBed().overrideProvider(TestComponentRenderer, { useValue: new CypressTestComponentRenderer() });
|
191
|
+
return componentFixture;
|
192
|
+
}
|
193
|
+
let WrapperComponent = class WrapperComponent {
|
194
|
+
};
|
195
|
+
WrapperComponent = __decorate([
|
196
|
+
Component({ selector: 'cy-wrapper-component', template: '' })
|
197
|
+
], WrapperComponent);
|
198
|
+
/**
|
199
|
+
* Returns the Component if Type<T> or creates a WrapperComponent
|
200
|
+
*
|
201
|
+
* @param {Type<T> | string} component The component you want to create a fixture of
|
202
|
+
* @returns {Type<T> | WrapperComponent}
|
203
|
+
*/
|
204
|
+
function createComponentFixture(component) {
|
205
|
+
if (typeof component === 'string') {
|
206
|
+
// getTestBed().overrideTemplate is available in v14+
|
207
|
+
// The static TestBed.overrideTemplate is available across versions
|
208
|
+
TestBed.overrideTemplate(WrapperComponent, component);
|
209
|
+
return WrapperComponent;
|
210
|
+
}
|
211
|
+
return component;
|
212
|
+
}
|
213
|
+
/**
|
214
|
+
* Creates the ComponentFixture
|
215
|
+
*
|
216
|
+
* @param {Type<T>} component Angular component being mounted
|
217
|
+
* @param {MountConfig<T>} config MountConfig
|
218
218
|
|
219
|
-
* @returns {ComponentFixture<T>} ComponentFixture
|
220
|
-
*/
|
221
|
-
function setupFixture(component, config) {
|
222
|
-
const fixture = getTestBed().createComponent(component);
|
223
|
-
setupComponent(config, fixture);
|
224
|
-
fixture.whenStable().then(() => {
|
225
|
-
var _a;
|
226
|
-
fixture.autoDetectChanges((_a = config.autoDetectChanges) !== null && _a !== void 0 ? _a : true);
|
227
|
-
});
|
228
|
-
return fixture;
|
229
|
-
}
|
230
|
-
/**
|
231
|
-
* Gets the componentInstance and Object.assigns any componentProperties() passed in the MountConfig
|
232
|
-
*
|
233
|
-
* @param {MountConfig} config TestBed configuration passed into the mount function
|
234
|
-
* @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
|
235
|
-
* @returns {T} Component being mounted
|
236
|
-
*/
|
237
|
-
function setupComponent(config, fixture) {
|
238
|
-
let component = fixture.componentInstance;
|
239
|
-
if (config === null || config === void 0 ? void 0 : config.componentProperties) {
|
240
|
-
component = Object.assign(component, config.componentProperties);
|
241
|
-
}
|
242
|
-
if (config.autoSpyOutputs) {
|
243
|
-
Object.keys(component).forEach((key) => {
|
244
|
-
const property = component[key];
|
245
|
-
if (property instanceof EventEmitter) {
|
246
|
-
component[key] = createOutputSpy(`${key}Spy`);
|
247
|
-
}
|
248
|
-
});
|
249
|
-
}
|
250
|
-
// Manually call ngOnChanges when mounting components using the class syntax.
|
251
|
-
// This is necessary because we are assigning input values to the class directly
|
252
|
-
// on mount and therefore the ngOnChanges() lifecycle is not triggered.
|
253
|
-
if (component.ngOnChanges && config.componentProperties) {
|
254
|
-
const { componentProperties } = config;
|
255
|
-
const simpleChanges = Object.entries(componentProperties).reduce((acc, [key, value]) => {
|
256
|
-
acc[key] = new SimpleChange(null, value, true);
|
257
|
-
return acc;
|
258
|
-
}, {});
|
259
|
-
if (Object.keys(componentProperties).length > 0) {
|
260
|
-
component.ngOnChanges(simpleChanges);
|
261
|
-
}
|
262
|
-
}
|
263
|
-
}
|
264
|
-
/**
|
265
|
-
* Mounts an Angular component inside Cypress browser
|
266
|
-
*
|
267
|
-
* @param component Angular component being mounted or its template
|
268
|
-
* @param config configuration used to configure the TestBed
|
269
|
-
* @example
|
270
|
-
* import { mount } from '@cypress/angular'
|
271
|
-
* import { StepperComponent } from './stepper.component'
|
272
|
-
* import { MyService } from 'services/my.service'
|
273
|
-
* import { SharedModule } from 'shared/shared.module';
|
274
|
-
* it('mounts', () => {
|
275
|
-
* mount(StepperComponent, {
|
276
|
-
* providers: [MyService],
|
277
|
-
* imports: [SharedModule]
|
278
|
-
* })
|
279
|
-
* cy.get('[data-cy=increment]').click()
|
280
|
-
* cy.get('[data-cy=counter]').should('have.text', '1')
|
281
|
-
* })
|
282
|
-
*
|
283
|
-
* // or
|
284
|
-
*
|
285
|
-
* it('mounts with template', () => {
|
286
|
-
* mount('<app-stepper></app-stepper>', {
|
287
|
-
* declarations: [StepperComponent],
|
288
|
-
* })
|
289
|
-
* })
|
290
|
-
*
|
291
|
-
* @see {@link https://on.cypress.io/mounting-angular} for more details.
|
292
|
-
*
|
293
|
-
* @returns A component and component fixture
|
294
|
-
*/
|
295
|
-
function mount(component, config = {}) {
|
296
|
-
// Remove last mounted component if cy.mount is called more than once in a test
|
297
|
-
if (activeFixture) {
|
298
|
-
cleanup();
|
299
|
-
}
|
300
|
-
const componentFixture = initTestBed(component, config);
|
301
|
-
activeFixture = setupFixture(componentFixture, config);
|
302
|
-
const mountResponse = {
|
303
|
-
fixture: activeFixture,
|
304
|
-
component: activeFixture.componentInstance,
|
305
|
-
};
|
306
|
-
const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name;
|
307
|
-
Cypress.log({
|
308
|
-
name: 'mount',
|
309
|
-
message: logMessage,
|
310
|
-
consoleProps: () => ({ result: mountResponse }),
|
311
|
-
});
|
312
|
-
return cy.wrap(mountResponse, { log: false });
|
313
|
-
}
|
314
|
-
/**
|
315
|
-
* Creates a new Event Emitter and then spies on it's `emit` method
|
316
|
-
*
|
317
|
-
* @param {string} alias name you want to use for your cy.spy() alias
|
318
|
-
* @returns EventEmitter<T>
|
319
|
-
* @example
|
320
|
-
* import { StepperComponent } from './stepper.component'
|
321
|
-
* import { mount, createOutputSpy } from '@cypress/angular'
|
322
|
-
*
|
323
|
-
* it('Has spy', () => {
|
324
|
-
* mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
|
325
|
-
* cy.get('[data-cy=increment]').click()
|
326
|
-
* cy.get('@changeSpy').should('have.been.called')
|
327
|
-
* })
|
328
|
-
*/
|
329
|
-
const createOutputSpy = (alias) => {
|
330
|
-
const emitter = new EventEmitter();
|
331
|
-
cy.spy(emitter, 'emit').as(alias);
|
332
|
-
return emitter;
|
333
|
-
};
|
334
|
-
// Only needs to run once, we reset before each test
|
335
|
-
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
|
336
|
-
teardown: { destroyAfterEach: false },
|
337
|
-
});
|
219
|
+
* @returns {ComponentFixture<T>} ComponentFixture
|
220
|
+
*/
|
221
|
+
function setupFixture(component, config) {
|
222
|
+
const fixture = getTestBed().createComponent(component);
|
223
|
+
setupComponent(config, fixture);
|
224
|
+
fixture.whenStable().then(() => {
|
225
|
+
var _a;
|
226
|
+
fixture.autoDetectChanges((_a = config.autoDetectChanges) !== null && _a !== void 0 ? _a : true);
|
227
|
+
});
|
228
|
+
return fixture;
|
229
|
+
}
|
230
|
+
/**
|
231
|
+
* Gets the componentInstance and Object.assigns any componentProperties() passed in the MountConfig
|
232
|
+
*
|
233
|
+
* @param {MountConfig} config TestBed configuration passed into the mount function
|
234
|
+
* @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
|
235
|
+
* @returns {T} Component being mounted
|
236
|
+
*/
|
237
|
+
function setupComponent(config, fixture) {
|
238
|
+
let component = fixture.componentInstance;
|
239
|
+
if (config === null || config === void 0 ? void 0 : config.componentProperties) {
|
240
|
+
component = Object.assign(component, config.componentProperties);
|
241
|
+
}
|
242
|
+
if (config.autoSpyOutputs) {
|
243
|
+
Object.keys(component).forEach((key) => {
|
244
|
+
const property = component[key];
|
245
|
+
if (property instanceof EventEmitter) {
|
246
|
+
component[key] = createOutputSpy(`${key}Spy`);
|
247
|
+
}
|
248
|
+
});
|
249
|
+
}
|
250
|
+
// Manually call ngOnChanges when mounting components using the class syntax.
|
251
|
+
// This is necessary because we are assigning input values to the class directly
|
252
|
+
// on mount and therefore the ngOnChanges() lifecycle is not triggered.
|
253
|
+
if (component.ngOnChanges && config.componentProperties) {
|
254
|
+
const { componentProperties } = config;
|
255
|
+
const simpleChanges = Object.entries(componentProperties).reduce((acc, [key, value]) => {
|
256
|
+
acc[key] = new SimpleChange(null, value, true);
|
257
|
+
return acc;
|
258
|
+
}, {});
|
259
|
+
if (Object.keys(componentProperties).length > 0) {
|
260
|
+
component.ngOnChanges(simpleChanges);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
/**
|
265
|
+
* Mounts an Angular component inside Cypress browser
|
266
|
+
*
|
267
|
+
* @param component Angular component being mounted or its template
|
268
|
+
* @param config configuration used to configure the TestBed
|
269
|
+
* @example
|
270
|
+
* import { mount } from '@cypress/angular'
|
271
|
+
* import { StepperComponent } from './stepper.component'
|
272
|
+
* import { MyService } from 'services/my.service'
|
273
|
+
* import { SharedModule } from 'shared/shared.module';
|
274
|
+
* it('mounts', () => {
|
275
|
+
* mount(StepperComponent, {
|
276
|
+
* providers: [MyService],
|
277
|
+
* imports: [SharedModule]
|
278
|
+
* })
|
279
|
+
* cy.get('[data-cy=increment]').click()
|
280
|
+
* cy.get('[data-cy=counter]').should('have.text', '1')
|
281
|
+
* })
|
282
|
+
*
|
283
|
+
* // or
|
284
|
+
*
|
285
|
+
* it('mounts with template', () => {
|
286
|
+
* mount('<app-stepper></app-stepper>', {
|
287
|
+
* declarations: [StepperComponent],
|
288
|
+
* })
|
289
|
+
* })
|
290
|
+
*
|
291
|
+
* @see {@link https://on.cypress.io/mounting-angular} for more details.
|
292
|
+
*
|
293
|
+
* @returns A component and component fixture
|
294
|
+
*/
|
295
|
+
function mount(component, config = {}) {
|
296
|
+
// Remove last mounted component if cy.mount is called more than once in a test
|
297
|
+
if (activeFixture) {
|
298
|
+
cleanup();
|
299
|
+
}
|
300
|
+
const componentFixture = initTestBed(component, config);
|
301
|
+
activeFixture = setupFixture(componentFixture, config);
|
302
|
+
const mountResponse = {
|
303
|
+
fixture: activeFixture,
|
304
|
+
component: activeFixture.componentInstance,
|
305
|
+
};
|
306
|
+
const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name;
|
307
|
+
Cypress.log({
|
308
|
+
name: 'mount',
|
309
|
+
message: logMessage,
|
310
|
+
consoleProps: () => ({ result: mountResponse }),
|
311
|
+
});
|
312
|
+
return cy.wrap(mountResponse, { log: false });
|
313
|
+
}
|
314
|
+
/**
|
315
|
+
* Creates a new Event Emitter and then spies on it's `emit` method
|
316
|
+
*
|
317
|
+
* @param {string} alias name you want to use for your cy.spy() alias
|
318
|
+
* @returns EventEmitter<T>
|
319
|
+
* @example
|
320
|
+
* import { StepperComponent } from './stepper.component'
|
321
|
+
* import { mount, createOutputSpy } from '@cypress/angular'
|
322
|
+
*
|
323
|
+
* it('Has spy', () => {
|
324
|
+
* mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
|
325
|
+
* cy.get('[data-cy=increment]').click()
|
326
|
+
* cy.get('@changeSpy').should('have.been.called')
|
327
|
+
* })
|
328
|
+
*/
|
329
|
+
const createOutputSpy = (alias) => {
|
330
|
+
const emitter = new EventEmitter();
|
331
|
+
cy.spy(emitter, 'emit').as(alias);
|
332
|
+
return emitter;
|
333
|
+
};
|
334
|
+
// Only needs to run once, we reset before each test
|
335
|
+
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
|
336
|
+
teardown: { destroyAfterEach: false },
|
337
|
+
});
|
338
338
|
setupHooks(cleanup);
|
339
339
|
|
340
340
|
export { CypressTestComponentRenderer, createOutputSpy, mount };
|
package/angular/dist/index.d.ts
CHANGED
@@ -56,7 +56,7 @@ interface MountConfig<T> extends TestModuleMetadata {
|
|
56
56
|
* Type that the `mount` function returns
|
57
57
|
* @type MountResponse<T>
|
58
58
|
*/
|
59
|
-
|
59
|
+
type MountResponse<T> = {
|
60
60
|
/**
|
61
61
|
* Fixture for debugging and testing a component.
|
62
62
|
*
|