mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 05:25:08 +00:00
add test for programmatic prefetch
This commit is contained in:
@@ -7,12 +7,13 @@
|
|||||||
|
|
||||||
<p>This is the 'about' page. There's not much here.</p>
|
<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>
|
</Layout>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Layout from './_components/Layout.html';
|
import Layout from './_components/Layout.html';
|
||||||
import { goto } from '../../../runtime.js';
|
import { goto, prefetch } from '../../../runtime.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -20,7 +21,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
goto
|
goto,
|
||||||
|
prefetch
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -166,7 +166,7 @@ function run(env) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('navigates to a new page without reloading', async () => {
|
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 () => {
|
const requests = await capture(async () => {
|
||||||
await nightmare.click('a[href="/about"]');
|
await nightmare.click('a[href="/about"]');
|
||||||
@@ -189,7 +189,7 @@ function run(env) {
|
|||||||
await nightmare
|
await nightmare
|
||||||
.goto(`${base}/about`)
|
.goto(`${base}/about`)
|
||||||
.wait(() => window.READY)
|
.wait(() => window.READY)
|
||||||
.click('button')
|
.click('.goto')
|
||||||
.wait(() => window.location.pathname === '/blog/what-is-sapper')
|
.wait(() => window.location.pathname === '/blog/what-is-sapper')
|
||||||
.wait(100);
|
.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 () => {
|
it('scrolls to active deeplink', async () => {
|
||||||
const scrollY = await nightmare
|
const scrollY = await nightmare
|
||||||
.goto(`${base}/blog/a-very-long-post#four`)
|
.goto(`${base}/blog/a-very-long-post#four`)
|
||||||
|
|||||||
Reference in New Issue
Block a user