cypress 13.12.0 → 13.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,6 @@ import { TestModuleMetadata, ComponentFixture, TestComponentRenderer } from '@an
7
7
  * Additional module configurations needed while mounting the component, like
8
8
  * providers, declarations, imports and even component @Inputs()
9
9
  *
10
- *
11
10
  * @interface MountConfig
12
11
  * @see https://angular.io/api/core/testing/TestModuleMetadata
13
12
  */
@@ -7,7 +7,6 @@ import { TestModuleMetadata, ComponentFixture, TestComponentRenderer } from '@an
7
7
  * Additional module configurations needed while mounting the component, like
8
8
  * providers, declarations, imports and even component @Inputs()
9
9
  *
10
- *
11
10
  * @interface MountConfig
12
11
  * @see https://angular.io/api/core/testing/TestModuleMetadata
13
12
  */
@@ -0,0 +1,11 @@
1
+ # @cypress/angular-signals
2
+
3
+ Mount Angular components in the open source [Cypress.io](https://www.cypress.io/) test runner. This package is an extension of `@cypress/angular`, but with [signals](https://angular.dev/guide/signals) support.
4
+
5
+ > **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [Angular Component Testing Docs](https://docs.cypress.io/guides/component-testing/angular/overview) for mounting Angular components. Installing and importing `mount` from `@cypress/angular-signals` should only be done for advanced use-cases.
6
+
7
+ ## Development
8
+
9
+ Run `yarn build` to compile and sync packages to the `cypress` cli package.
10
+
11
+ ## [Changelog](./CHANGELOG.md)
@@ -0,0 +1,11 @@
1
+ # @cypress/angular-signals
2
+
3
+ Mount Angular components in the open source [Cypress.io](https://www.cypress.io/) test runner. This package is an extension of `@cypress/angular`, but with [signals](https://angular.dev/guide/signals) support.
4
+
5
+ > **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [Angular Component Testing Docs](https://docs.cypress.io/guides/component-testing/angular/overview) for mounting Angular components. Installing and importing `mount` from `@cypress/angular-signals` should only be done for advanced use-cases.
6
+
7
+ ## Development
8
+
9
+ Run `yarn build` to compile and sync packages to the `cypress` cli package.
10
+
11
+ ## [Changelog](./CHANGELOG.md)
@@ -0,0 +1,136 @@
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
+ * @description flag to automatically create a cy.spy() for every component @Output() property
17
+ * @example
18
+ * export class ButtonComponent {
19
+ * @Output clicked = new EventEmitter()
20
+ * }
21
+ *
22
+ * cy.mount(ButtonComponent, { autoSpyOutputs: true })
23
+ * cy.get('@clickedSpy).should('have.been.called')
24
+ */
25
+ autoSpyOutputs?: boolean;
26
+ /**
27
+ * @memberof MountConfig
28
+ * @description flag defaulted to true to automatically detect changes in your components
29
+ */
30
+ autoDetectChanges?: boolean;
31
+ /**
32
+ * @memberof MountConfig
33
+ * @example
34
+ * import { ButtonComponent } from 'button/button.component'
35
+ * it('renders a button with Save text', () => {
36
+ * cy.mount(ButtonComponent, { componentProperties: { text: 'Save' }})
37
+ * cy.get('button').contains('Save')
38
+ * })
39
+ *
40
+ * it('renders a button with a cy.spy() replacing EventEmitter', () => {
41
+ * cy.mount(ButtonComponent, {
42
+ * componentProperties: {
43
+ * clicked: cy.spy().as('mySpy)
44
+ * }
45
+ * })
46
+ * cy.get('button').click()
47
+ * cy.get('@mySpy').should('have.been.called')
48
+ * })
49
+ */
50
+ componentProperties?: Partial<{
51
+ [P in keyof T]: T[P] extends InputSignal<infer V> ? InputSignal<V> | WritableSignal<V> | V : T[P];
52
+ }>;
53
+ }
54
+ /**
55
+ * Type that the `mount` function returns
56
+ * @type MountResponse<T>
57
+ */
58
+ type MountResponse<T> = {
59
+ /**
60
+ * Fixture for debugging and testing a component.
61
+ *
62
+ * @memberof MountResponse
63
+ * @see https://angular.io/api/core/testing/ComponentFixture
64
+ */
65
+ fixture: ComponentFixture<T>;
66
+ /**
67
+ * The instance of the root component class
68
+ *
69
+ * @memberof MountResponse
70
+ * @see https://angular.io/api/core/testing/ComponentFixture#componentInstance
71
+ */
72
+ component: T;
73
+ };
74
+ declare class CypressTestComponentRenderer extends TestComponentRenderer {
75
+ insertRootElement(rootElId: string): void;
76
+ removeAllRootElements(): void;
77
+ }
78
+ /**
79
+ * Mounts an Angular component inside Cypress browser
80
+ *
81
+ * @param component Angular component being mounted or its template
82
+ * @param config configuration used to configure the TestBed
83
+ * @example
84
+ * import { mount } from '@cypress/angular-signals'
85
+ * import { StepperComponent } from './stepper.component'
86
+ * import { MyService } from 'services/my.service'
87
+ * import { SharedModule } from 'shared/shared.module';
88
+ * it('mounts', () => {
89
+ * mount(StepperComponent, {
90
+ * providers: [MyService],
91
+ * imports: [SharedModule]
92
+ * })
93
+ * cy.get('[data-cy=increment]').click()
94
+ * cy.get('[data-cy=counter]').should('have.text', '1')
95
+ * })
96
+ *
97
+ * // or
98
+ *
99
+ * it('mounts with template', () => {
100
+ * mount('<app-stepper></app-stepper>', {
101
+ * declarations: [StepperComponent],
102
+ * })
103
+ * })
104
+ *
105
+ * @see {@link https://on.cypress.io/mounting-angular} for more details.
106
+ *
107
+ * @returns A component and component fixture
108
+ */
109
+ declare function mount<T>(component: Type<T> | string, config?: MountConfig<T>): Cypress.Chainable<MountResponse<T>>;
110
+ /**
111
+ * Creates a new Event Emitter and then spies on it's `emit` method
112
+ *
113
+ * @param {string} alias name you want to use for your cy.spy() alias
114
+ * @returns EventEmitter<T>
115
+ * @example
116
+ * import { StepperComponent } from './stepper.component'
117
+ * import { mount, createOutputSpy } from '@cypress/angular-signals'
118
+ *
119
+ * it('Has spy', () => {
120
+ * mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
121
+ * cy.get('[data-cy=increment]').click()
122
+ * cy.get('@changeSpy').should('have.been.called')
123
+ * })
124
+ *
125
+ * // Or for use with Angular Signals following the output nomenclature.
126
+ * // see https://v17.angular.io/guide/model-inputs#differences-between-model-and-input/
127
+ *
128
+ * it('Has spy', () => {
129
+ * mount(StepperComponent, { componentProperties: { count: signal(0), countChange: createOutputSpy('countChange') } })
130
+ * cy.get('[data-cy=increment]').click()
131
+ * cy.get('@countChange').should('have.been.called')
132
+ * })
133
+ */
134
+ declare const createOutputSpy: <T>(alias: string) => any;
135
+
136
+ export { CypressTestComponentRenderer, MountConfig, MountResponse, createOutputSpy, mount };