Skip to content

Commit eb82f0b

Browse files
committed
update 05
1 parent 85678ff commit eb82f0b

41 files changed

Lines changed: 5566 additions & 18857 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

05-testing/03-e2e/05-custom-commands/.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

05-testing/03-e2e/05-custom-commands/README.md

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ We will start from `04-wait-requests`.
1212
npm install
1313
```
1414

15-
- If we look into our code, we will notice that there some steps that we're going to want to repeat over the tests:
15+
If we look into our code, we will notice that there some steps that we're going to want to repeat over the tests:
1616

17-
### ./cypress/support/commands.ts
17+
_./cypress/support/commands.ts_
1818

1919
```javascript
2020
Cypress.Commands.add('loadAndVisit', () => {
@@ -27,37 +27,16 @@ Cypress.Commands.add('loadAndVisit', () => {
2727
```
2828
> Note: we will fix typings errors adding a d.ts file
2929
30-
### ./cypress/support/e2e.ts
30+
_./cypress/support/e2e.ts_
3131

3232
```diff
3333
import '@testing-library/cypress/add-commands';
3434
+ import './commands';
3535
```
3636

37-
- Use it:
37+
We will need add `d.ts` file to support new method:
3838

39-
### ./cypress/e2e/hotel-collection.spec.ts
40-
41-
```diff
42-
...
43-
it('should fetch hotel list and show it in screen when visit /hotel-collection url', () => {
44-
// Arrange
45-
- cy.intercept('GET', '/api/hotels').as('fetchHotels');
46-
47-
// Act
48-
- cy.visit('/hotel-collection');
49-
+ cy.loadAndVisit();
50-
51-
// Assert
52-
- cy.wait('@fetchHotels');
53-
cy.findAllByRole('listitem').should('have.length', 10);
54-
});
55-
...
56-
```
57-
58-
- We will need add `d.ts` file to support new method:
59-
60-
### ./cypress/support/index.d.ts
39+
_./cypress/support/index.d.ts_
6140

6241
```typescript
6342
declare namespace Cypress {
@@ -67,18 +46,13 @@ declare namespace Cypress {
6746
}
6847
```
6948

70-
### ./cypress/tsconfig.json
49+
_./cypress/tsconfig.json_
7150

7251
```diff
7352
{
7453
"compilerOptions": {
75-
"strict": true,
76-
"baseUrl": "../node_modules",
7754
"target": "es5",
7855
"lib": ["es5", "dom"],
79-
"esModuleInterop": true,
80-
"noImplicitAny": false,
81-
"allowJs": true,
8256
- "types": ["cypress", "@testing-library/cypress"]
8357
+ "types": ["cypress", "@testing-library/cypress", "./support"]
8458
},
@@ -90,9 +64,30 @@ declare namespace Cypress {
9064

9165
> More info [here](https://docs.cypress.io/guides/tooling/typescript-support.html#Types-for-custom-assertions)
9266
93-
- Update specs:
67+
Use it:
68+
69+
_./cypress/e2e/hotel-collection.spec.ts_
70+
71+
```diff
72+
...
73+
it('should fetch hotel list and show it in screen when visit /hotel-collection url', () => {
74+
// Arrange
75+
- cy.intercept('GET', '/api/hotels').as('fetchHotels');
76+
77+
// Act
78+
- cy.visit('/hotel-collection');
79+
+ cy.loadAndVisit();
80+
81+
// Assert
82+
- cy.wait('@fetchHotels');
83+
cy.findAllByRole('listitem').should('have.length', 10);
84+
});
85+
...
86+
```
87+
88+
Update specs:
9489

95-
### ./cypress/e2e/hotel-collection.spec.ts
90+
_./cypress/e2e/hotel-collection.spec.ts_
9691

9792
```diff
9893
...
@@ -110,9 +105,9 @@ it('should fetch hotel list greater than 0 when visit /hotel-collection url', ()
110105
});
111106
```
112107

113-
- Even, we could pass parameters if we want to be more generic:
108+
Even, we could pass parameters if we want to be more generic:
114109

115-
### ./cypress/support/commands.ts
110+
_./cypress/support/commands.ts_
116111

117112
```diff
118113
- Cypress.Commands.add('loadAndVisit', () => {
@@ -132,9 +127,9 @@ it('should fetch hotel list greater than 0 when visit /hotel-collection url', ()
132127

133128
```
134129

135-
- Update typings:
130+
Update typings:
136131

137-
### ./cypress/support/index.d.ts
132+
_./cypress/support/index.d.ts_
138133

139134
```diff
140135
declare namespace Cypress {
@@ -150,9 +145,9 @@ declare namespace Cypress {
150145

151146
```
152147

153-
- Update it:
148+
Update it:
154149

155-
### ./cypress/e2e/hotel-collection.spec.ts
150+
_./cypress/e2e/hotel-collection.spec.ts_
156151

157152
```diff
158153
...
@@ -180,13 +175,11 @@ declare namespace Cypress {
180175

181176
it('should fetch two hotels when visit /hotel-collection url', () => {
182177
// Arrange
183-
- cy.intercept('GET', '/api/hotels', {
184-
- fixture: 'hotels.json',
185-
- }).as('fetchHotels');
178+
- cy.intercept('GET', '/api/hotels', { fixture: 'hotels' }).as('fetchHotels');
186179

187180
// Act
188181
- cy.visit('/hotel-collection');
189-
+ cy.loadAndVisit('/api/hotels', '/hotel-collection', 'hotels.json');
182+
+ cy.loadAndVisit('/api/hotels', '/hotel-collection', 'hotels');
190183

191184
// Assert
192185
- cy.wait('@fetchHotels');

05-testing/03-e2e/05-custom-commands/config/webpack/base.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

05-testing/03-e2e/05-custom-commands/config/webpack/dev.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

05-testing/03-e2e/05-custom-commands/config/webpack/helpers.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

05-testing/03-e2e/05-custom-commands/config/webpack/prod.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

05-testing/03-e2e/05-custom-commands/cypress/e2e/hotel-collection.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
describe('Hotel collection specs', () => {
22
it('should fetch hotel list and show it in screen when visit /hotel-collection url', () => {
33
// Arrange
4-
54
// Act
65
cy.loadAndVisit('/api/hotels', '/hotel-collection');
76

@@ -23,7 +22,7 @@ describe('Hotel collection specs', () => {
2322
// Arrange
2423

2524
// Act
26-
cy.loadAndVisit('/api/hotels', '/hotel-collection', 'hotels.json');
25+
cy.loadAndVisit('/api/hotels', '/hotel-collection', 'hotels');
2726

2827
// Assert
2928
cy.findAllByRole('listitem').should('have.length', 2);

05-testing/03-e2e/05-custom-commands/cypress/e2e/login.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('Login specs', () => {
88

99
// Act
1010
cy.visit('/');
11-
cy.findByLabelText('Name').click();
11+
cy.findByRole('textbox').click();
1212

1313
// Assert
14-
cy.findByLabelText('Name').should('have.focus');
14+
cy.findByRole('textbox').should('have.focus');
1515
});
1616

1717
it('should show an alert with a message when type invalid credentials', () => {
@@ -22,7 +22,7 @@ describe('Login specs', () => {
2222

2323
// Act
2424
cy.visit('/');
25-
cy.findByLabelText('Name').as('userInput');
25+
cy.findByRole('textbox').as('userInput');
2626
cy.findByLabelText('Password').as('passwordInput');
2727

2828
cy.get('@userInput').type(user);
@@ -53,6 +53,6 @@ describe('Login specs', () => {
5353
cy.findByRole('button', { name: 'Login' }).click();
5454

5555
// Assert
56-
cy.url().should('eq', 'http://localhost:8080/#/hotel-collection');
56+
cy.url().should('equal', 'http://localhost:8080/#/hotel-collection');
5757
});
5858
});

05-testing/03-e2e/05-custom-commands/cypress/support/commands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Cypress.Commands.add(
55
? cy.intercept('GET', apiPath, { fixture }).as('load')
66
: cy.intercept('GET', apiPath).as('load');
77
cy.visit(routePath);
8-
98
cy.wait('@load');
109
}
1110
);

05-testing/03-e2e/05-custom-commands/dev.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)