mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 05:25:08 +00:00
clear errors on successful render
This commit is contained in:
@@ -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 = {
|
const data = {
|
||||||
path,
|
path,
|
||||||
preloading: false,
|
preloading: false,
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ export class AppRunner {
|
|||||||
start: () => this.page.evaluate(() => start()),
|
start: () => this.page.evaluate(() => start()),
|
||||||
prefetchRoutes: () => this.page.evaluate(() => prefetchRoutes()),
|
prefetchRoutes: () => this.page.evaluate(() => prefetchRoutes()),
|
||||||
prefetch: (href: string) => this.page.evaluate((href: string) => prefetch(href), href),
|
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)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
test/apps/errors/src/routes/enhance-your-calm.html
Normal file
7
test/apps/errors/src/routes/enhance-your-calm.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
preload() {
|
||||||
|
this.error(420, 'Enhance your calm');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
3
test/apps/errors/src/routes/no-error.html
Normal file
3
test/apps/errors/src/routes/no-error.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<h1>{error ? error.message : 'No error here'}</h1>
|
||||||
|
|
||||||
|
<a href="enhance-your-calm">Enhance your calm</a>
|
||||||
@@ -14,13 +14,14 @@ describe('errors', function() {
|
|||||||
// helpers
|
// helpers
|
||||||
let start: () => Promise<void>;
|
let start: () => Promise<void>;
|
||||||
let prefetchRoutes: () => Promise<void>;
|
let prefetchRoutes: () => Promise<void>;
|
||||||
|
let title: () => Promise<string>;
|
||||||
|
|
||||||
// hooks
|
// hooks
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await build({ cwd: __dirname });
|
await build({ cwd: __dirname });
|
||||||
|
|
||||||
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
|
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());
|
after(() => runner.end());
|
||||||
@@ -110,4 +111,16 @@ describe('errors', function() {
|
|||||||
'oops'
|
'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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user