From 64e5065aa5d2ec14af85410a96d9ae8e6b6fc9cd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 16 Oct 2018 15:59:57 -0400 Subject: [PATCH] clear errors on successful render --- templates/src/client/app.ts | 2 +- test/apps/AppRunner.ts | 3 ++- .../apps/errors/src/routes/enhance-your-calm.html | 7 +++++++ test/apps/errors/src/routes/no-error.html | 3 +++ test/apps/errors/test.ts | 15 ++++++++++++++- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/apps/errors/src/routes/enhance-your-calm.html create mode 100644 test/apps/errors/src/routes/no-error.html diff --git a/templates/src/client/app.ts b/templates/src/client/app.ts index 3773c37..43b0764 100644 --- a/templates/src/client/app.ts +++ b/templates/src/client/app.ts @@ -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, diff --git a/test/apps/AppRunner.ts b/test/apps/AppRunner.ts index 6a1a48c..077a3b7 100644 --- a/test/apps/AppRunner.ts +++ b/test/apps/AppRunner.ts @@ -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) }; } diff --git a/test/apps/errors/src/routes/enhance-your-calm.html b/test/apps/errors/src/routes/enhance-your-calm.html new file mode 100644 index 0000000..398584e --- /dev/null +++ b/test/apps/errors/src/routes/enhance-your-calm.html @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/apps/errors/src/routes/no-error.html b/test/apps/errors/src/routes/no-error.html new file mode 100644 index 0000000..8dc116a --- /dev/null +++ b/test/apps/errors/src/routes/no-error.html @@ -0,0 +1,3 @@ +

{error ? error.message : 'No error here'}

+ +Enhance your calm \ No newline at end of file diff --git a/test/apps/errors/test.ts b/test/apps/errors/test.ts index 57a7dbc..158bbbc 100644 --- a/test/apps/errors/test.ts +++ b/test/apps/errors/test.ts @@ -14,13 +14,14 @@ describe('errors', function() { // helpers let start: () => Promise; let prefetchRoutes: () => Promise; + let title: () => Promise; // 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'); + }); }); \ No newline at end of file