add test for programmatic prefetch

This commit is contained in:
Rich Harris
2018-01-03 13:46:07 -05:00
parent e87ac1f367
commit 50e307e0c0
2 changed files with 21 additions and 5 deletions

View File

@@ -166,7 +166,7 @@ function run(env) {
});
it('navigates to a new page without reloading', async () => {
await nightmare.goto(base).wait(() => window.READY).wait(100);
await nightmare.goto(base).wait(() => window.READY).wait(200);
const requests = await capture(async () => {
await nightmare.click('a[href="/about"]');
@@ -189,7 +189,7 @@ function run(env) {
await nightmare
.goto(`${base}/about`)
.wait(() => window.READY)
.click('button')
.click('.goto')
.wait(() => window.location.pathname === '/blog/what-is-sapper')
.wait(100);
@@ -199,6 +199,20 @@ function run(env) {
);
});
it('prefetches programmatically', async () => {
await nightmare
.goto(`${base}/about`)
.wait(() => window.READY);
const requests = await capture(async () => {
return await nightmare
.click('.prefetch')
.wait(100);
});
assert.ok(!!requests.find(r => r.url === '/api/blog/why-the-name'));
});
it('scrolls to active deeplink', async () => {
const scrollY = await nightmare
.goto(`${base}/blog/a-very-long-post#four`)