clear errors on successful render

This commit is contained in:
Rich Harris
2018-10-16 15:59:57 -04:00
parent cb45bb0fbe
commit 64e5065aa5
5 changed files with 27 additions and 3 deletions

View File

@@ -310,7 +310,7 @@ export function prepare_page(target: Target): Promise<{
};
}
const props = { path, query };
const props = { path, query, error: null, status: null };
const data = {
path,
preloading: false,

View File

@@ -58,7 +58,8 @@ export class AppRunner {
start: () => this.page.evaluate(() => start()),
prefetchRoutes: () => this.page.evaluate(() => prefetchRoutes()),
prefetch: (href: string) => this.page.evaluate((href: string) => prefetch(href), href),
goto: (href: string) => this.page.evaluate((href: string) => goto(href), href)
goto: (href: string) => this.page.evaluate((href: string) => goto(href), href),
title: () => this.page.$eval('h1', node => node.textContent)
};
}

View File

@@ -0,0 +1,7 @@
<script>
export default {
preload() {
this.error(420, 'Enhance your calm');
}
};
</script>

View File

@@ -0,0 +1,3 @@
<h1>{error ? error.message : 'No error here'}</h1>
<a href="enhance-your-calm">Enhance your calm</a>

View File

@@ -14,13 +14,14 @@ describe('errors', function() {
// helpers
let start: () => Promise<void>;
let prefetchRoutes: () => Promise<void>;
let title: () => Promise<string>;
// hooks
before(async () => {
await build({ cwd: __dirname });
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
({ base, page, start, prefetchRoutes } = await runner.start());
({ base, page, start, prefetchRoutes, title } = await runner.start());
});
after(() => runner.end());
@@ -110,4 +111,16 @@ describe('errors', function() {
'oops'
);
});
it('clears props.error on successful render', async () => {
await page.goto(`${base}/no-error`);
await start();
await prefetchRoutes();
await page.click('[href="enhance-your-calm"]');
assert.equal(await title(), '420');
await page.goBack();
assert.equal(await title(), 'No error here');
});
});