Skip to content

Commit

Permalink
feat(testing): support cypress 11 (nrwl#13075)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Nov 9, 2022
1 parent a218149 commit 37c8483
Show file tree
Hide file tree
Showing 11 changed files with 913 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Angular Cypress Component Test Generator should generate a component test 1`] = `
"import { MountConfig } from 'cypress/angular';
"import { TestBed } from '@angular/core/testing';
import { MyLibComponent } from './my-lib.component';
describe(MyLibComponent.name, () => {
const config: MountConfig<MyLibComponent> = {
declarations: [],
imports: [],
providers: []
}
beforeEach(() => {
TestBed.overrideComponent(MyLibComponent, {
add: {
imports: [],
providers: []
}
})
})
it('renders', () => {
cy.mount(MyLibComponent, {
...config,
componentProperties: {
type: 'button',
style: 'default',
Expand All @@ -22,42 +25,51 @@ describe(MyLibComponent.name, () => {
}
});
})
})
"
`;

exports[`Angular Cypress Component Test Generator should handle component w/o inputs 1`] = `
"import { MountConfig } from 'cypress/angular';
"import { TestBed } from '@angular/core/testing';
import { MyLibComponent } from './my-lib.component';
describe(MyLibComponent.name, () => {
const config: MountConfig<MyLibComponent> = {
declarations: [],
imports: [],
providers: []
}
beforeEach(() => {
TestBed.overrideComponent(MyLibComponent, {
add: {
imports: [],
providers: []
}
})
})
it('renders', () => {
cy.mount(MyLibComponent, config);
cy.mount(MyLibComponent,);
})
})
"
`;

exports[`Angular Cypress Component Test Generator should work with standalone components 1`] = `
"import { MountConfig } from 'cypress/angular';
"import { TestBed } from '@angular/core/testing';
import { MyLibComponent } from './my-lib.component';
describe(MyLibComponent.name, () => {
const config: MountConfig<MyLibComponent> = {
declarations: [],
imports: [],
providers: []
}
beforeEach(() => {
TestBed.overrideComponent(MyLibComponent, {
add: {
imports: [],
providers: []
}
})
})
it('renders', () => {
cy.mount(MyLibComponent, {
...config,
componentProperties: {
type: 'button',
style: 'default',
Expand All @@ -66,6 +78,7 @@ describe(MyLibComponent.name, () => {
}
});
})
})
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,24 @@ export class MyLibComponent implements OnInit {

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

const expected = `import { MountConfig } from 'cypress/angular';
const expected = `import { TestBed } from '@angular/core/testing';
import { MyLibComponent } from './my-lib.component';
describe(MyLibComponent.name, () => {
const config: MountConfig<MyLibComponent> = {
declarations: [],
imports: [],
providers: []
}
beforeEach(() => {
TestBed.overrideComponent(MyLibComponent, {
add: {
imports: [],
providers: []
}
})
})
it('renders', () => {
cy.mount(MyLibComponent, config);
cy.mount(MyLibComponent,);
})
})
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { MountConfig } from 'cypress/angular';
import { TestBed } from '@angular/core/testing';
import { <%= componentName %> } from './<%= componentFileName %>';

describe(<%= componentName %>.name, () => {
const config: MountConfig<<%= componentName %>> = {
declarations: [],
imports: [],
providers: []
}

beforeEach(() => {
TestBed.overrideComponent(<%= componentName %>, {
add: {
imports: [],
providers: []
}
})
})

it('renders', () => {
cy.mount(<%= componentName %>,<% if(props.length > 0) { %> {
...config,
componentProperties: {<% for (let prop of props) { %>
<%= prop.name %>: <%- prop.defaultValue %>,<% } %>
}
}<% } else { %> config<% } %>);
}<% } %>);
})

})
Loading

0 comments on commit 37c8483

Please sign in to comment.