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

@@ -7,12 +7,13 @@
<p>This is the 'about' page. There's not much here.</p>
<button on:click='goto("/blog/what-is-sapper")'>What is Sapper?</button>
<button class='goto' on:click='goto("/blog/what-is-sapper")'>What is Sapper?</button>
<button class='prefetch' on:click='goto("/blog/why-the-name")'>Why the name?</button>
</Layout>
<script>
import Layout from './_components/Layout.html';
import { goto } from '../../../runtime.js';
import { goto, prefetch } from '../../../runtime.js';
export default {
components: {
@@ -20,7 +21,8 @@
},
methods: {
goto
goto,
prefetch
}
};
</script>

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`)