Skip to content

Commit b54eac5

Browse files
ref(angular): rename config inputs to componentProperties
1 parent c42c939 commit b54eac5

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

npm/angular/src/mount.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export interface TestBedConfig<T extends object> extends TestModuleMetadata {
3434
* @example
3535
* import { ButtonComponent } from 'button/button.component'
3636
* it('renders a button with Save text', () => {
37-
* cy.mount(ButtonComponent, { inputs: { text: 'Save' }})
37+
* cy.mount(ButtonComponent, { componentProperties: { text: 'Save' }})
3838
* cy.get('button').contains('Save')
3939
* })
4040
*/
41-
inputs?: Partial<{ [P in keyof T]: T[P] }>
41+
componentProperties?: Partial<{ [P in keyof T]: T[P] }>
4242
}
4343

4444
/**
@@ -82,7 +82,7 @@ function bootstrapModule<T extends object> (
8282
component: Type<T>,
8383
config: TestBedConfig<T>,
8484
): TestBedConfig<T> {
85-
const { inputs, ...testModuleMetaData } = config
85+
const { componentProperties, ...testModuleMetaData } = config
8686

8787
if (!testModuleMetaData.declarations) {
8888
testModuleMetaData.declarations = []
@@ -164,7 +164,7 @@ function setupFixture<T extends object> (
164164
}
165165

166166
/**
167-
* Gets the componentInstance and Object.assigns any inputs() passed in the TestBedConfig
167+
* Gets the componentInstance and Object.assigns any componentProperties() passed in the TestBedConfig
168168
*
169169
* @param {TestBedConfig} config TestBed configuration passed into the mount function
170170
* @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
@@ -176,8 +176,8 @@ function setupComponent<T extends object> (
176176
): T {
177177
let component: T = fixture.componentInstance
178178

179-
if (config?.inputs) {
180-
component = Object.assign(component, config.inputs)
179+
if (config?.componentProperties) {
180+
component = Object.assign(component, config.componentProperties)
181181
}
182182

183183
return component

npm/webpack-dev-server/cypress/e2e/angular.cy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for (const project of WEBPACK_REACT) {
7575

7676
cy.contains('mount.cy.ts').click()
7777
cy.waitForSpecToFinish()
78-
cy.get('.passed > .num').should('contain', 5)
78+
cy.get('.passed > .num').should('contain', 6)
7979
})
8080
})
8181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component, EventEmitter, Output } from "@angular/core";
2+
3+
@Component({
4+
template: `<button (click)="clicked.emit(true)">Click Me</button>`
5+
})
6+
export class ButtonOutputComponent {
7+
@Output() clicked: EventEmitter<boolean> = new EventEmitter()
8+
}

system-tests/project-fixtures/angular/src/app/mount.cy.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CounterComponent } from "./components/counter.component";
44
import { CounterService } from "./components/counter.service";
55
import { ChildComponent } from "./components/child.component";
66
import { WithDirectivesComponent } from "./components/with-directives.component";
7+
import { ButtonOutputComponent } from "./components/button-output.component";
78

89
describe("angular mount", () => {
910
it("pushes CommonModule into component", () => {
@@ -32,7 +33,7 @@ describe("angular mount", () => {
3233
});
3334

3435
it("detects changes", () => {
35-
cy.mount(ChildComponent, { inputs: { msg: "Hello World from Spec" } })
36+
cy.mount(ChildComponent, { componentProperties: { msg: "Hello World from Spec" } })
3637
.then(({ fixture }) =>
3738
cy.contains("h1", "Hello World from Spec").wrap(fixture)
3839
)
@@ -42,4 +43,12 @@ describe("angular mount", () => {
4243
cy.contains("h1", "I just changed!");
4344
});
4445
});
46+
47+
it('can spy on EventEmitters', () => {
48+
cy.mount(ButtonOutputComponent).then(({ component }) => {
49+
cy.spy(component.clicked, 'emit').as('mySpy')
50+
cy.get('button').click()
51+
cy.get('@mySpy').should('have.been.calledWith', true)
52+
})
53+
})
4554
});

0 commit comments

Comments
 (0)