Skip to content

Commit 37c8483

Browse files
feat(testing): support cypress 11 (#13075)
1 parent a218149 commit 37c8483

File tree

11 files changed

+913
-136
lines changed

11 files changed

+913
-136
lines changed
Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Angular Cypress Component Test Generator should generate a component test 1`] = `
4-
"import { MountConfig } from 'cypress/angular';
4+
"import { TestBed } from '@angular/core/testing';
55
import { MyLibComponent } from './my-lib.component';
66
77
describe(MyLibComponent.name, () => {
8-
const config: MountConfig<MyLibComponent> = {
9-
declarations: [],
10-
imports: [],
11-
providers: []
12-
}
8+
9+
beforeEach(() => {
10+
TestBed.overrideComponent(MyLibComponent, {
11+
add: {
12+
imports: [],
13+
providers: []
14+
}
15+
})
16+
})
1317
1418
it('renders', () => {
1519
cy.mount(MyLibComponent, {
16-
...config,
1720
componentProperties: {
1821
type: 'button',
1922
style: 'default',
@@ -22,42 +25,51 @@ describe(MyLibComponent.name, () => {
2225
}
2326
});
2427
})
28+
2529
})
2630
"
2731
`;
2832

2933
exports[`Angular Cypress Component Test Generator should handle component w/o inputs 1`] = `
30-
"import { MountConfig } from 'cypress/angular';
34+
"import { TestBed } from '@angular/core/testing';
3135
import { MyLibComponent } from './my-lib.component';
3236
3337
describe(MyLibComponent.name, () => {
34-
const config: MountConfig<MyLibComponent> = {
35-
declarations: [],
36-
imports: [],
37-
providers: []
38-
}
38+
39+
beforeEach(() => {
40+
TestBed.overrideComponent(MyLibComponent, {
41+
add: {
42+
imports: [],
43+
providers: []
44+
}
45+
})
46+
})
3947
4048
it('renders', () => {
41-
cy.mount(MyLibComponent, config);
49+
cy.mount(MyLibComponent,);
4250
})
51+
4352
})
4453
"
4554
`;
4655

4756
exports[`Angular Cypress Component Test Generator should work with standalone components 1`] = `
48-
"import { MountConfig } from 'cypress/angular';
57+
"import { TestBed } from '@angular/core/testing';
4958
import { MyLibComponent } from './my-lib.component';
5059
5160
describe(MyLibComponent.name, () => {
52-
const config: MountConfig<MyLibComponent> = {
53-
declarations: [],
54-
imports: [],
55-
providers: []
56-
}
61+
62+
beforeEach(() => {
63+
TestBed.overrideComponent(MyLibComponent, {
64+
add: {
65+
imports: [],
66+
providers: []
67+
}
68+
})
69+
})
5770
5871
it('renders', () => {
5972
cy.mount(MyLibComponent, {
60-
...config,
6173
componentProperties: {
6274
type: 'button',
6375
style: 'default',
@@ -66,6 +78,7 @@ describe(MyLibComponent.name, () => {
6678
}
6779
});
6880
})
81+
6982
})
7083
"
7184
`;

packages/angular/src/generators/component-test/component-test.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,24 @@ export class MyLibComponent implements OnInit {
177177

178178
await componentGenerator(tree, { name: 'my-lib', project: 'my-lib' });
179179

180-
const expected = `import { MountConfig } from 'cypress/angular';
180+
const expected = `import { TestBed } from '@angular/core/testing';
181181
import { MyLibComponent } from './my-lib.component';
182182
183183
describe(MyLibComponent.name, () => {
184-
const config: MountConfig<MyLibComponent> = {
185-
declarations: [],
186-
imports: [],
187-
providers: []
188-
}
184+
185+
beforeEach(() => {
186+
TestBed.overrideComponent(MyLibComponent, {
187+
add: {
188+
imports: [],
189+
providers: []
190+
}
191+
})
192+
})
189193
190194
it('renders', () => {
191-
cy.mount(MyLibComponent, config);
195+
cy.mount(MyLibComponent,);
192196
})
197+
193198
})
194199
`;
195200

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { MountConfig } from 'cypress/angular';
1+
import { TestBed } from '@angular/core/testing';
22
import { <%= componentName %> } from './<%= componentFileName %>';
33

44
describe(<%= componentName %>.name, () => {
5-
const config: MountConfig<<%= componentName %>> = {
6-
declarations: [],
7-
imports: [],
8-
providers: []
9-
}
5+
6+
beforeEach(() => {
7+
TestBed.overrideComponent(<%= componentName %>, {
8+
add: {
9+
imports: [],
10+
providers: []
11+
}
12+
})
13+
})
1014

1115
it('renders', () => {
1216
cy.mount(<%= componentName %>,<% if(props.length > 0) { %> {
13-
...config,
1417
componentProperties: {<% for (let prop of props) { %>
1518
<%= prop.name %>: <%- prop.defaultValue %>,<% } %>
1619
}
17-
}<% } else { %> config<% } %>);
20+
}<% } %>);
1821
})
22+
1923
})

0 commit comments

Comments
 (0)