Skip to content

Commit f9630bc

Browse files
committed
Remove unnecessary awaits
1 parent 2a5e0ac commit f9630bc

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/content/5/en/part5d.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const { test, expect } = require('@playwright/test')
195195
test('front page can be opened', async ({ page }) => {
196196
await page.goto('http://localhost:5173')
197197

198-
const locator = await page.getByText('Notes')
198+
const locator = page.getByText('Notes')
199199
await expect(locator).toBeVisible()
200200
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2024')).toBeVisible()
201201
})
@@ -230,7 +230,7 @@ describe('Note app', () => { // highlight-line
230230
test('front page can be opened', async ({ page }) => {
231231
await page.goto('http://localhost:5173')
232232

233-
const locator = await page.getByText('Notes')
233+
const locator = page.getByText('Notes')
234234
await expect(locator).toBeVisible()
235235
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2025')).toBeVisible()
236236
})
@@ -429,7 +429,7 @@ describe('Note app', () => {
429429
// highlight-end
430430

431431
test('front page can be opened', async ({ page }) => {
432-
const locator = await page.getByText('Notes')
432+
const locator = page.getByText('Notes')
433433
await expect(locator).toBeVisible()
434434
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2024')).toBeVisible()
435435
})
@@ -996,7 +996,7 @@ describe('when logged in', () => {
996996
})
997997

998998
test('one of those can be made nonimportant', async ({ page }) => {
999-
const otherNoteElement = await page.getByText('first note')
999+
const otherNoteElement = page.getByText('first note')
10001000

10011001
await otherNoteElement
10021002
.getByRole('button', { name: 'make not important' }).click()
@@ -1012,7 +1012,7 @@ The test could also have been written without the auxiliary variable:
10121012
10131013
```js
10141014
test('one of those can be made nonimportant', async ({ page }) => {
1015-
await page.getByText('first note')
1015+
page.getByText('first note')
10161016
.getByRole('button', { name: 'make not important' }).click()
10171017

10181018
await expect(page.getByText('first note').getByText('make important'))
@@ -1036,13 +1036,13 @@ const Note = ({ note, toggleImportance }) => {
10361036
}
10371037
```
10381038
1039-
Tests break! The reason for the problem is that the command _await page.getByText('first note')_ now returns a _span_ element containing only text, and the button is outside of it.
1039+
Tests break! The reason for the problem is that the command _page.getByText('first note')_ now returns a _span_ element containing only text, and the button is outside of it.
10401040
10411041
One way to fix the problem is as follows:
10421042
10431043
```js
10441044
test('one of those can be made nonimportant', async ({ page }) => {
1045-
const otherNoteText = await page.getByText('first note') // highlight-line
1045+
const otherNoteText = page.getByText('first note') // highlight-line
10461046
const otherNoteElement = await otherNoteText.locator('..') // highlight-line
10471047

10481048
await otherNoteElement.getByRole('button', { name: 'make not important' }).click()
@@ -1056,7 +1056,7 @@ Of course, the test can also be written using only one auxiliary variable:
10561056
10571057
```js
10581058
test('one of those can be made nonimportant', async ({ page }) => {
1059-
const secondNoteElement = await page.getByText('second note').locator('..')
1059+
const secondNoteElement = page.getByText('second note').locator('..')
10601060
await secondNoteElement.getByRole('button', { name: 'make not important' }).click()
10611061
await expect(secondNoteElement.getByText('make important')).toBeVisible()
10621062
})
@@ -1083,7 +1083,7 @@ describe('when logged in', () => {
10831083
})
10841084

10851085
test('importance can be changed', async ({ page }) => {
1086-
const otherNoteText = await page.getByText('second note') // highlight-line
1086+
const otherNoteText = page.getByText('second note') // highlight-line
10871087
const otherNoteElement = await otherNoteText.locator('..')
10881088

10891089
await otherNoteElement.getByRole('button', { name: 'make not important' }).click()
@@ -1131,7 +1131,7 @@ describe('Note app', () => {
11311131

11321132
test('one of those can be made nonimportant', async ({ page }) => {
11331133
await page.pause() // highlight-line
1134-
const otherNoteText = await page.getByText('second note')
1134+
const otherNoteText = page.getByText('second note')
11351135
const otherNoteElement = await otherNoteText.locator('..')
11361136

11371137
await otherNoteElement.getByRole('button', { name: 'make not important' }).click()

src/content/5/fi/osa5d.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const { test, expect } = require('@playwright/test')
158158
test('front page can be opened', async ({ page }) => {
159159
await page.goto('http://localhost:5173')
160160

161-
const locator = await page.getByText('Notes')
161+
const locator = page.getByText('Notes')
162162
await expect(locator).toBeVisible()
163163
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2024')).toBeVisible()
164164
})
@@ -194,7 +194,7 @@ describe('Note app', () => {
194194
test('front page can be opened', async ({ page }) => {
195195
await page.goto('http://localhost:5173')
196196

197-
const locator = await page.getByText('Notes')
197+
const locator = page.getByText('Notes')
198198
await expect(locator).toBeVisible()
199199
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2025')).toBeVisible()
200200
})
@@ -390,7 +390,7 @@ describe('Note app', () => {
390390
// highlight-end
391391

392392
test('front page can be opened', async ({ page }) => {
393-
const locator = await page.getByText('Notes')
393+
const locator = page.getByText('Notes')
394394
await expect(locator).toBeVisible()
395395
await expect(page.getByText('Note app, Department of Computer Science, University of Helsinki 2024')).toBeVisible()
396396
})
@@ -659,7 +659,7 @@ Voisimmekin tarkentaa testiä varmistamaan, että virheilmoitus tulostuu nimenom
659659
test('login fails with wrong password', async ({ page }) => {
660660
// ...
661661

662-
const errorDiv = await page.locator('.error')
662+
const errorDiv = page.locator('.error')
663663
await expect(errorDiv).toContainText('wrong credentials')
664664
})
665665
```
@@ -672,7 +672,7 @@ Ekspekaatiolla [toHaveCSS](https://playwright.dev/docs/api/class-locatorassertio
672672
test('login fails with wrong password', async ({ page }) => {
673673
// ...
674674

675-
const errorDiv = await page.locator('.error')
675+
const errorDiv = page.locator('.error')
676676
await expect(errorDiv).toContainText('wrong credentials')
677677
await expect(errorDiv).toHaveCSS('border-style', 'solid')
678678
await expect(errorDiv).toHaveCSS('color', 'rgb(255, 0, 0)')
@@ -690,7 +690,7 @@ test('login fails with wrong password', async ({ page }) =>{
690690
await page.getByLabel('password').fill('wrong')
691691
await page.getByRole('button', { name: 'login' }).click()
692692

693-
const errorDiv = await page.locator('.error')
693+
const errorDiv = page.locator('.error')
694694
await expect(errorDiv).toContainText('wrong credentials')
695695
await expect(errorDiv).toHaveCSS('border-style', 'solid')
696696
await expect(errorDiv).toHaveCSS('color', 'rgb(255, 0, 0)')
@@ -954,7 +954,7 @@ describe('when logged in', () => {
954954
})
955955

956956
test('one of those can be made nonimportant', async ({ page }) => {
957-
const otherNoteElement = await page.getByText('first note')
957+
const otherNoteElement = page.getByText('first note')
958958

959959
await otherNoteElement
960960
.getByRole('button', { name: 'make not important' }).click()
@@ -970,7 +970,7 @@ Testi olisi voitu kirjoittaa myös ilman apumuuttujaa:
970970
971971
```js
972972
test('one of those can be made nonimportant', async ({ page }) => {
973-
await page.getByText('first note')
973+
page.getByText('first note')
974974
.getByRole('button', { name: 'make not important' }).click()
975975

976976
await expect(page.getByText('first note').getByText('make important'))
@@ -994,13 +994,13 @@ const Note = ({ note, toggleImportance }) => {
994994
}
995995
```
996996
997-
Testit hajoavat! Syynä ongelmalle on se, komento _await page.getByText('second note')_ palauttaakin nyt ainoastaan tekstin sisältävän _span_-elementin, ja nappi on sen ulkopuolella.
997+
Testit hajoavat! Syynä ongelmalle on se, komento _page.getByText('second note')_ palauttaakin nyt ainoastaan tekstin sisältävän _span_-elementin, ja nappi on sen ulkopuolella.
998998
999999
Eräs tapa korjata ongelma on seuraavassa:
10001000
10011001
```js
10021002
test('one of those can be made nonimportant', async ({ page }) => {
1003-
const otherNoteText = await page.getByText('first note') // highlight-line
1003+
const otherNoteText = page.getByText('first note') // highlight-line
10041004
const otherdNoteElement = await otherNoteText.locator('..') // highlight-line
10051005

10061006
await otherdNoteElement.getByRole('button', { name: 'make not important' }).click()
@@ -1014,7 +1014,7 @@ Testi voidaan toki kirjoittaa myös ainoastaan yhtä apumuuttujaa käyttäen:
10141014
10151015
```js
10161016
test('one of those can be made nonimportant', async ({ page }) => {
1017-
const secondNoteElement = await page.getByText('second note').locator('..')
1017+
const secondNoteElement = page.getByText('second note').locator('..')
10181018
await secondNoteElement.getByRole('button', { name: 'make not important' }).click()
10191019
await expect(secondNoteElement.getByText('make important')).toBeVisible()
10201020
})
@@ -1041,7 +1041,7 @@ describe('when logged in', () => {
10411041
})
10421042

10431043
test('importance can be changed', async ({ page }) => {
1044-
const otherNoteText = await page.getByText('second note') // highlight-line
1044+
const otherNoteText = page.getByText('second note') // highlight-line
10451045
const otherdNoteElement = await otherNoteText.locator('..')
10461046

10471047
await otherdNoteElement.getByRole('button', { name: 'make not important' }).click()
@@ -1089,7 +1089,7 @@ describe('Note app', () => {
10891089

10901090
test('one of those can be made unimportant', async ({ page }) => {
10911091
await page.pause() // highlight-line
1092-
const otherNoteText = await page.getByText('second note')
1092+
const otherNoteText = page.getByText('second note')
10931093
const otherdNoteElement = await otherNoteText.locator('..')
10941094

10951095
await otherdNoteElement.getByRole('button', { name: 'make not important' }).click()

0 commit comments

Comments
 (0)