mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
always re-run preload functions when query string changes - fixes #701
This commit is contained in:
17
test/apps/preloading/src/routes/echo/index.svelte
Normal file
17
test/apps/preloading/src/routes/echo/index.svelte
Normal file
@@ -0,0 +1,17 @@
|
||||
<script context="module">
|
||||
export function preload(page) {
|
||||
return {
|
||||
query: page.query
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let query;
|
||||
</script>
|
||||
|
||||
<pre>{JSON.stringify(query)}</pre>
|
||||
|
||||
<a href="echo?foo=1">foo=1</a>
|
||||
<a href="echo?foo=2">foo=2</a>
|
||||
<a href="echo?foo=3">foo=3</a>
|
||||
@@ -109,4 +109,23 @@ describe('preloading', function() {
|
||||
it('survives the tests with no server errors', () => {
|
||||
assert.deepEqual(r.errors, []);
|
||||
});
|
||||
|
||||
it('re-runs preload when page.query changes', async () => {
|
||||
await r.load('/echo?foo=1');
|
||||
await r.sapper.start();
|
||||
await r.sapper.prefetchRoutes();
|
||||
|
||||
assert.equal(
|
||||
await r.text('pre'),
|
||||
`{"foo":"1"}`
|
||||
);
|
||||
|
||||
await r.page.click('a[href="echo?foo=2"]');
|
||||
await r.wait();
|
||||
|
||||
assert.equal(
|
||||
await r.text('pre'),
|
||||
`{"foo":"2"}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user