mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +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>
|
||||
|
||||
<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>
|
||||
@@ -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`)
|
||||
|
||||
Reference in New Issue
Block a user