Skip to content

Commit 7248f86

Browse files
committed
[test] Deflake shallow-routing
1 parent e68639f commit 7248f86

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

test/development/pages-dir/client-navigation/shallow-routing.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env jest */
22

3-
import { waitFor } from 'next-test-utils'
3+
import { retry, waitFor } from 'next-test-utils'
44
import path from 'path'
55
import { nextTestSetup } from 'e2e-utils'
66

@@ -14,14 +14,16 @@ describe('Client navigation with shallow routing', () => {
1414

1515
it('should update the url without running getInitialProps', async () => {
1616
const browser = await next.browser('/nav/shallow-routing')
17-
const counter = await browser
17+
await browser
1818
.elementByCss('#increase')
1919
.click()
2020
.elementByCss('#increase')
2121
.click()
22-
.elementByCss('#counter')
23-
.text()
24-
expect(counter).toBe('Counter: 2')
22+
23+
await retry(async () => {
24+
const counter = await browser.elementByCss('#counter').text()
25+
expect(counter).toBe('Counter: 2')
26+
})
2527

2628
const getInitialPropsRunCount = await browser
2729
.elementByCss('#get-initial-props-run-count')
@@ -33,17 +35,23 @@ describe('Client navigation with shallow routing', () => {
3335

3436
it('should handle the back button and should not run getInitialProps', async () => {
3537
const browser = await next.browser('/nav/shallow-routing')
36-
let counter = await browser
38+
await browser
3739
.elementByCss('#increase')
3840
.click()
3941
.elementByCss('#increase')
4042
.click()
41-
.elementByCss('#counter')
42-
.text()
43-
expect(counter).toBe('Counter: 2')
4443

45-
counter = await browser.back().elementByCss('#counter').text()
46-
expect(counter).toBe('Counter: 1')
44+
await retry(async () => {
45+
const counter = await browser.elementByCss('#counter').text()
46+
expect(counter).toBe('Counter: 2')
47+
})
48+
49+
await browser.back()
50+
51+
await retry(async () => {
52+
const counter = await browser.elementByCss('#counter').text()
53+
expect(counter).toBe('Counter: 1')
54+
})
4755

4856
const getInitialPropsRunCount = await browser
4957
.elementByCss('#get-initial-props-run-count')

0 commit comments

Comments
 (0)