Skip to content

Commit 48b8b56

Browse files
committed
kit: update basics routes test to wait for navigation on click
1 parent a4c4d46 commit 48b8b56

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

packages/kit/test/apps/basics/src/routes/accessibility/__tests__.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as assert from 'uvu/assert';
44
export default function (test) {
55
// TODO unskip this
66
test.skip('resets focus', '/accessibility/a', async ({ page }) => {
7-
await page.click('[href="/accessibility/b"]');
7+
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/b"]')]);
88
await page.waitForTimeout(50);
99
assert.equal(await page.innerHTML('h1'), 'b');
1010
await page.waitForTimeout(50);
@@ -14,7 +14,7 @@ export default function (test) {
1414
assert.equal(await page.evaluate(() => document.activeElement.nodeName), 'A');
1515
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'a');
1616

17-
await page.click('[href="/accessibility/a"]');
17+
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/a"]')]);
1818
await page.waitForTimeout(50);
1919
assert.equal(await page.innerHTML('h1'), 'a');
2020
assert.equal(await page.evaluate(() => document.activeElement.nodeName), 'BODY');
@@ -33,7 +33,7 @@ export default function (test) {
3333
// live region should exist, but be empty
3434
assert.equal(await page.innerHTML('[aria-live]'), '');
3535

36-
await page.click('[href="/accessibility/b"]');
36+
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/b"]')]);
3737
await page.waitForTimeout(50);
3838
assert.equal(await page.innerHTML('[aria-live]'), 'Navigated to b'); // TODO i18n
3939
} else {

packages/kit/test/apps/basics/src/routes/delete-route/__tests__.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as assert from 'uvu/assert';
44
export default function (test) {
55
test('calls a delete handler', '/delete-route', async ({ page, js }) => {
66
if (js) {
7-
await page.click('.del');
7+
await Promise.all([page.waitForNavigation(), page.click('.del')]);
88
await page.waitForSelector('h1');
99

1010
assert.equal(await page.innerHTML('h1'), 'deleted 42');

packages/kit/test/apps/basics/src/routes/preload/__tests__.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as assert from 'uvu/assert';
33
/** @type {import('../../../../../types').TestMaker} */
44
export default function test(test) {
55
test('errors on preload', '/preload', async ({ page }) => {
6-
await page.click('[href="/preload/uses-preload"]');
6+
await Promise.all([page.waitForNavigation(), page.click('[href="/preload/uses-preload"]')]);
77

88
assert.equal(await page.textContent('h1'), '500');
99
assert.equal(await page.textContent('footer'), 'Custom layout');

packages/kit/test/apps/basics/src/routes/redirect/__tests__.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as assert from 'uvu/assert';
33
/** @type {import('../../../../../types').TestMaker} */
44
export default function (test, is_dev) {
55
test('redirect', '/redirect', async ({ base, page, js }) => {
6-
await page.click('[href="/redirect/a"]');
6+
await Promise.all([page.waitForNavigation(), page.click('[href="/redirect/a"]')]);
77

88
if (js) await page.waitForTimeout(50);
99

@@ -12,7 +12,7 @@ export default function (test, is_dev) {
1212
});
1313

1414
test('prevents redirect loops', '/redirect', async ({ base, page, js }) => {
15-
await page.click('[href="/redirect/loopy/a"]');
15+
await Promise.all([page.waitForNavigation(), page.click('[href="/redirect/loopy/a"]')]);
1616

1717
if (js) {
1818
await page.waitForTimeout(50);
@@ -30,7 +30,10 @@ export default function (test, is_dev) {
3030
});
3131

3232
test('errors on missing status', '/redirect', async ({ base, page, js }) => {
33-
await page.click('[href="/redirect/missing-status/a"]');
33+
await Promise.all([
34+
page.waitForNavigation(),
35+
page.click('[href="/redirect/missing-status/a"]')
36+
]);
3437

3538
if (js) await page.waitForTimeout(50);
3639

@@ -43,7 +46,10 @@ export default function (test, is_dev) {
4346
});
4447

4548
test('errors on invalid status', '/redirect', async ({ base, page, js }) => {
46-
await page.click('[href="/redirect/missing-status/b"]');
49+
await Promise.all([
50+
page.waitForNavigation(),
51+
page.click('[href="/redirect/missing-status/b"]')
52+
]);
4753

4854
if (js) await page.waitForTimeout(50);
4955

packages/kit/test/apps/basics/src/routes/routing/__tests__.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function (test) {
66
'redirects from /routing/ to /routing',
77
'/routing/slashes',
88
async ({ base, page, app, js }) => {
9-
await page.click('a[href="/routing/"]');
9+
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/"]')]);
1010
assert.equal(await page.url(), `${base}/routing`);
1111
assert.equal(await page.textContent('h1'), 'Great success!');
1212

@@ -24,7 +24,7 @@ export default function (test) {
2424
'redirects from /routing/? to /routing',
2525
'/routing/slashes',
2626
async ({ base, page, app, js }) => {
27-
await page.click('a[href="/routing/?"]');
27+
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/?"]')]);
2828
assert.equal(await page.url(), `${base}/routing`);
2929
assert.equal(await page.textContent('h1'), 'Great success!');
3030

@@ -42,7 +42,7 @@ export default function (test) {
4242
'redirects from /routing/?foo=bar to /routing?foo=bar',
4343
'/routing/slashes',
4444
async ({ base, page, app, js }) => {
45-
await page.click('a[href="/routing/?foo=bar"]');
45+
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/?foo=bar"]')]);
4646
assert.equal(await page.url(), `${base}/routing?foo=bar`);
4747
assert.equal(await page.textContent('h1'), 'Great success!');
4848

@@ -97,7 +97,7 @@ export default function (test) {
9797
await page.waitForTimeout(500);
9898

9999
const requests = await capture_requests(async () => {
100-
await page.click('a[href="/routing/a"]');
100+
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/a"]')]);
101101

102102
await page.waitForFunction(() => document.location.pathname == '/routing/a');
103103

@@ -126,7 +126,10 @@ export default function (test) {
126126
});
127127

128128
test('does not attempt client-side navigation to server routes', '/routing', async ({ page }) => {
129-
await page.click('[href="/routing/ambiguous/ok.json"]');
129+
await Promise.all([
130+
page.waitForNavigation(),
131+
page.click('[href="/routing/ambiguous/ok.json"]')
132+
]);
130133
await page.waitForFunction(() => document.location.pathname == '/routing/ambiguous/ok.json');
131134

132135
assert.equal(await page.textContent('body'), 'ok');
@@ -137,13 +140,13 @@ export default function (test) {
137140
});
138141

139142
test('resets the active element after navigation', '/routing', async ({ page }) => {
140-
await page.click('[href="/routing/a"]');
143+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/a"]')]);
141144
await page.waitForFunction(() => document.activeElement.nodeName == 'BODY');
142145
});
143146

144147
test('navigates between routes with empty parts', '/routing/dirs/foo', async ({ page }) => {
145148
assert.equal(await page.textContent('h1'), 'foo');
146-
await page.click('[href="bar"]');
149+
await Promise.all([page.waitForNavigation(), page.click('[href="bar"]')]);
147150
await page.waitForSelector('.bar');
148151

149152
assert.equal(await page.textContent('h1'), 'bar');
@@ -152,27 +155,30 @@ export default function (test) {
152155
test('navigates to ...rest', '/routing/abc/xyz', async ({ page }) => {
153156
assert.equal(await page.textContent('h1'), 'abc,xyz');
154157

155-
await page.click('[href="/routing/xyz/abc/def/ghi"]');
158+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/xyz/abc/def/ghi"]')]);
156159
assert.equal(await page.textContent('h1'), 'xyz,abc,def,ghi');
157160
assert.equal(await page.textContent('h2'), 'xyz,abc,def,ghi');
158161

159-
await page.click('[href="/routing/xyz/abc/def"]');
162+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/xyz/abc/def"]')]);
160163
assert.equal(await page.textContent('h1'), 'xyz,abc,def');
161164
assert.equal(await page.textContent('h2'), 'xyz,abc,def');
162165

163-
await page.click('[href="/routing/xyz/abc/def"]');
166+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/xyz/abc/def"]')]);
164167
assert.equal(await page.textContent('h1'), 'xyz,abc,def');
165168
assert.equal(await page.textContent('h2'), 'xyz,abc,def');
166169

167-
await page.click('[href="/routing/xyz/abc"]');
170+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/xyz/abc"]')]);
168171
assert.equal(await page.textContent('h1'), 'xyz,abc');
169172
assert.equal(await page.textContent('h2'), 'xyz,abc');
170173

171-
await page.click('[href="/routing/xyz/abc/deep"]');
174+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/xyz/abc/deep"]')]);
172175
assert.equal(await page.textContent('h1'), 'xyz,abc');
173176
assert.equal(await page.textContent('h2'), 'xyz,abc');
174177

175-
await page.click('[href="/routing/xyz/abc/qwe/deep.json"]');
178+
await Promise.all([
179+
page.waitForNavigation(),
180+
page.click('[href="/routing/xyz/abc/qwe/deep.json"]')
181+
]);
176182
assert.equal(await page.textContent('body'), 'xyz,abc,qwe');
177183
});
178184

@@ -182,25 +188,25 @@ export default function (test) {
182188
async ({ page }) => {
183189
assert.equal(await page.textContent('h1'), 'A page');
184190

185-
await page.click('[href="/routing/dirs/foo/xyz"]');
191+
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/dirs/foo/xyz"]')]);
186192
assert.equal(await page.textContent('h1'), 'B page');
187193
}
188194
);
189195

190196
test('find regexp routes', '/routing/qwe', async ({ page }) => {
191197
assert.equal(await page.textContent('h1'), 'qwe');
192198

193-
await page.click('[href="234"]');
199+
await Promise.all([page.waitForNavigation(), page.click('[href="234"]')]);
194200
assert.equal(await page.textContent('h1'), 'Regexp page 234');
195201

196-
await page.click('[href="regexp/234"]');
202+
await Promise.all([page.waitForNavigation(), page.click('[href="regexp/234"]')]);
197203
assert.equal(await page.textContent('h1'), 'Nested regexp page 234');
198204
});
199205

200206
test('invalidates page when a segment is skipped', '/routing/skipped/x/1', async ({ page }) => {
201207
assert.equal(await page.textContent('h1'), 'x/1');
202208

203-
await page.click('#goto-y1');
209+
await Promise.all([page.waitForNavigation(), page.click('#goto-y1')]);
204210
assert.equal(await page.textContent('h1'), 'y/1');
205211
});
206212
}

packages/kit/test/apps/basics/src/routes/session/__tests__.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function (test) {
77
assert.equal(await page.innerHTML('h2'), 'answer via store: 42');
88

99
if (js) {
10-
await page.click('button');
10+
await Promise.all([page.waitForNavigation(), page.click('button')]);
1111
await page.waitForTimeout(1);
1212
assert.equal(await page.innerHTML('h1'), 'answer via props: 43');
1313
assert.equal(await page.innerHTML('h2'), 'answer via store: 43');

packages/kit/test/apps/basics/src/routes/store/__tests__.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function (test) {
66
assert.equal(await page.textContent('h1'), 'Test');
77
assert.equal(await page.textContent('h2'), 'Calls: 1');
88

9-
await page.click('a[href="/store/result"]');
9+
await Promise.all([page.waitForNavigation(), page.click('a[href="/store/result"]')]);
1010
assert.equal(await page.textContent('h1'), 'Result');
1111
assert.equal(await page.textContent('h2'), js ? 'Calls: 1' : 'Calls: 0');
1212

@@ -18,7 +18,7 @@ export default function (test) {
1818
assert.equal(await page.textContent('#navigating'), 'not currently navigating');
1919

2020
if (js) {
21-
await page.click('a[href="/store/navigating/b"]');
21+
await Promise.all([page.waitForNavigation(), page.click('a[href="/store/navigating/b"]')]);
2222

2323
assert.equal(
2424
await page.textContent('#navigating'),

0 commit comments

Comments
 (0)