You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/5/en/part5.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ lang: en
8
8
9
9
In this part we return to the frontend, first looking at different possibilities for testing the React code. We will also implement token based authentication which will enable users to log in to our application.
We also made a small change to the script that starts the application, without the change Cypress can not access the app.
58
+
55
59
Unlike the frontend's unit tests, Cypress tests can be in the frontend or the backend repository, or even in their separate repository.
56
60
57
61
The tests require the tested system to be running. Unlike our backend integration tests, Cypress tests <i>do not start</i> the system when they are run.
@@ -107,7 +111,7 @@ Let us change the test content as follows:
107
111
```js
108
112
describe('Note app', function() {
109
113
it('front page can be opened', function() {
110
-
cy.visit('http://localhost:3000')
114
+
cy.visit('http://localhost:5173')
111
115
cy.contains('Notes')
112
116
cy.contains('Note app, Department of Computer Science, University of Helsinki 2023')
113
117
})
@@ -130,7 +134,7 @@ We could have declared the test using an arrow function
130
134
```js
131
135
describe('Note app', () => { // highlight-line
132
136
it('front page can be opened', () => { // highlight-line
133
-
cy.visit('http://localhost:3000')
137
+
cy.visit('http://localhost:5173')
134
138
cy.contains('Notes')
135
139
cy.contains('Note app, Department of Computer Science, University of Helsinki 2023')
136
140
})
@@ -144,14 +148,14 @@ If <i>cy.contains</i> does not find the text it is searching for, the test does
144
148
```js
145
149
describe('Note app', function() {
146
150
it('front page can be opened', function() {
147
-
cy.visit('http://localhost:3000')
151
+
cy.visit('http://localhost:5173')
148
152
cy.contains('Notes')
149
153
cy.contains('Note app, Department of Computer Science, University of Helsinki 2023')
150
154
})
151
155
152
156
// highlight-start
153
157
it('front page contains random text', function() {
154
-
cy.visit('http://localhost:3000')
158
+
cy.visit('http://localhost:5173')
155
159
cy.contains('wtf is this app?')
156
160
})
157
161
// highlight-end
@@ -174,28 +178,28 @@ We can get rid of it by installing [eslint-plugin-cypress](https://github.com/cy
174
178
npm install eslint-plugin-cypress --save-dev
175
179
```
176
180
177
-
and changing the configuration in <i>.eslintrc.js</i> like so:
181
+
and changing the configuration in <i>.eslintrc.cjs</i> like so:
The test first searches for the login button by its text and clicks the button with the command [cy.click](https://docs.cypress.io/api/commands/click.html#Syntax).
221
225
222
-
Both of our tests begin the same way, by opening the page <i><http://localhost:3000></i>, so we should
226
+
Both of our tests begin the same way, by opening the page <i><http://localhost:5173></i>, so we should
223
227
separate the shared part into a <i>beforeEach</i> block run before each test:
@@ -716,7 +720,7 @@ First, we test logging in. Then, in their own describe block, we have a bunch of
716
720
717
721
As we said above, each test starts from zero! Tests do not start from the state where the previous tests ended.
718
722
719
-
The Cypress documentation gives us the following advice: [Fully test the login flow – but only once!](https://docs.cypress.io/guides/end-to-end-testing/testing-your-app#Fully-test-the-login-flow-but-only-once).
723
+
The Cypress documentation gives us the following advice: [Fully test the login flow – but only once](https://docs.cypress.io/guides/end-to-end-testing/testing-your-app#Fully-test-the-login-flow-but-only-once).
720
724
So instead of logging in a user using the form in the <i>beforeEach</i> block, Cypress recommends that we [bypass the UI](https://docs.cypress.io/guides/getting-started/testing-your-app.html#Bypassing-your-UI) and do an HTTP request to the backend to log in. The reason for this is that logging in with an HTTP request is much faster than filling out a form.
721
725
722
726
Our situation is a bit more complicated than in the example in the Cypress documentation because when a user logs in, our application saves their details to the localStorage.
There is one more annoying feature in our tests. The application address <i>http:localhost:3000</i> is hardcoded in many places.
868
+
There is one more annoying feature in our tests. The application address <i>http:localhost:5173</i> is hardcoded in many places.
865
869
866
870
Let's define the <i>baseUrl</i> for the application in the Cypress pre-generated [configuration file](https://docs.cypress.io/guides/references/configuration) <i>cypress.config.js</i>:
Copy file name to clipboardExpand all lines: src/content/5/fi/osa5.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ lang: fi
8
8
9
9
Tässä osassa palataan frontendin pariin, ensin tarkastellaan erilaisia tarjolla olevia mahdollisuuksia React-sovelluksen testaamiseen. Osassa myös toteutetaan frontendiin tokeneihin perustuva autentikaatio, joka mahdollistaa käyttäjien kirjautumisen sovellukseen.
0 commit comments