Skip to content

Commit 2f06913

Browse files
committed
update 02-selectors
1 parent 1261783 commit 2f06913

41 files changed

Lines changed: 5539 additions & 18829 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/00-boilerplate/dev.env

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

05-testing/03-e2e/01-config/dev.env

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

05-testing/03-e2e/02-selectors/.babelrc

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

05-testing/03-e2e/02-selectors/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ We will start from `01-config`.
1212
npm install
1313
```
1414

15-
- Let's add some specs to login page:
15+
Let's add some specs to login page:
1616

17-
### ./cypress/e2e/login.spec.ts
17+
_./cypress/e2e/login.spec.ts_
1818

1919
```diff
2020
...
@@ -35,9 +35,9 @@ npm install
3535

3636
```
3737

38-
- Notice that we are using selectors like css selectors, the first refactor that we could think is assign selectors to a variable like:
38+
Notice that we are using selectors like css selectors, the first refactor that we could think is assign selectors to a variable like:
3939

40-
### ./cypress/e2e/login.spec.ts
40+
_./cypress/e2e/login.spec.ts_
4141

4242
```diff
4343
...
@@ -66,9 +66,9 @@ npm install
6666

6767
```
6868

69-
- This doesn't work, because `cypress commands` are enqueued and run it in async way. Let's refactor it:
69+
This doesn't work, because `cypress commands` are enqueued and run it in async way. Let's refactor it:
7070

71-
### ./cypress/e2e/login.spec.ts
71+
_./cypress/e2e/login.spec.ts_
7272

7373
```diff
7474
...
@@ -102,15 +102,15 @@ npm install
102102

103103
> More info [here](https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Return-Values)
104104
105-
- The [get](https://docs.cypress.io/api/commands/get.html) return DOM element by selector or alias. But we want to write maintainable tests with same syntax like unit tests. We can use [cypress-testing-library](https://github.com/testing-library/cypress-testing-library):
105+
The [get](https://docs.cypress.io/api/commands/get.html) return DOM element by selector or alias. But we want to write maintainable tests with same syntax like unit tests. We can use [cypress-testing-library](https://github.com/testing-library/cypress-testing-library):
106106

107107
```bash
108108
npm install @testing-library/cypress --save-dev
109109
```
110110

111-
- Let's configure it for typescript:
111+
Let's configure it for typescript:
112112

113-
### ./cypress/tsconfig.json
113+
_./cypress/tsconfig.json_
114114

115115
```diff
116116
{
@@ -125,15 +125,15 @@ npm install @testing-library/cypress --save-dev
125125

126126
```
127127

128-
### ./cypress/support/e2e.ts
128+
_./cypress/support/e2e.ts_
129129

130130
```diff
131-
+ import '@testing-library/cypress/add-commands'
131+
+ import '@testing-library/cypress/add-commands';
132132
```
133133

134-
- Update specs:
134+
Update specs:
135135

136-
### ./cypress/e2e/login.spec.ts
136+
_./cypress/e2e/login.spec.ts_
137137

138138
```diff
139139
describe('Login specs', () => {
@@ -181,9 +181,9 @@ describe('Login specs', () => {
181181
>
182182
> [Which query should I use?](https://testing-library.com/docs/guide-which-query)
183183
184-
- Checking modal error message when click on button with invalid credentials:
184+
Checking modal error message when click on button with invalid credentials:
185185

186-
### ./cypress/e2e/login.spec.ts
186+
_./cypress/e2e/login.spec.ts_
187187

188188
```diff
189189
...
@@ -218,9 +218,9 @@ describe('Login specs', () => {
218218
>
219219
> This stub is not necessary if we use the Snackbar component or similar.
220220
221-
- Now, we could test when it's a succeded login:
221+
Now, we could test when it's a succeded login:
222222

223-
### ./cypress/e2e/login.spec.ts
223+
_./cypress/e2e/login.spec.ts_
224224

225225
```diff
226226
...

05-testing/03-e2e/02-selectors/config/webpack/base.js

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

05-testing/03-e2e/02-selectors/config/webpack/dev.js

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

05-testing/03-e2e/02-selectors/config/webpack/helpers.js

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

05-testing/03-e2e/02-selectors/config/webpack/prod.js

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

05-testing/03-e2e/02-selectors/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/02-selectors/dev.env

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

0 commit comments

Comments
 (0)