mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
add session tests
This commit is contained in:
@@ -2,11 +2,6 @@ import * as sapper from '@sapper/app';
|
||||
|
||||
window.start = () => sapper.start({
|
||||
target: document.querySelector('#sapper')
|
||||
}).catch(err => {
|
||||
console.error(`OH NO! ${err.message}`);
|
||||
throw err;
|
||||
}).then(() => {
|
||||
console.log(`STARTED`);
|
||||
});
|
||||
|
||||
window.prefetchRoutes = () => sapper.prefetchRoutes();
|
||||
|
||||
18
test/apps/session/src/routes/preloaded.html
Normal file
18
test/apps/session/src/routes/preloaded.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<script context="module">
|
||||
export function preload(page, { title }) {
|
||||
return { title };
|
||||
};
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { getSession } from '@sapper/app';
|
||||
const session = getSession();
|
||||
|
||||
export let title;
|
||||
</script>
|
||||
|
||||
<h1>{title}</h1>
|
||||
|
||||
<button on:click="{() => session.set({ title: 'changed' })}">
|
||||
click me
|
||||
</button>
|
||||
10
test/apps/session/src/routes/session.html
Normal file
10
test/apps/session/src/routes/session.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<script>
|
||||
import { getSession } from '@sapper/app';
|
||||
const session = getSession();
|
||||
</script>
|
||||
|
||||
<h1>{$session.title}</h1>
|
||||
|
||||
<button on:click="{() => session.set({ title: 'changed' })}">
|
||||
click me
|
||||
</button>
|
||||
@@ -3,7 +3,7 @@ import * as puppeteer from 'puppeteer';
|
||||
import { build } from '../../../api';
|
||||
import { AppRunner } from '../AppRunner';
|
||||
|
||||
describe('store', function() {
|
||||
describe('session', function() {
|
||||
this.timeout(10000);
|
||||
|
||||
let runner: AppRunner;
|
||||
@@ -24,12 +24,27 @@ describe('store', function() {
|
||||
|
||||
after(() => runner.end());
|
||||
|
||||
it('renders store props', async () => {
|
||||
await page.goto(`${base}/store`);
|
||||
it('renders session props', async () => {
|
||||
await page.goto(`${base}/session`);
|
||||
|
||||
assert.equal(await title(), 'hello world');
|
||||
|
||||
await start();
|
||||
assert.equal(await title(), 'hello world');
|
||||
|
||||
await page.click('button');
|
||||
assert.equal(await title(), 'changed');
|
||||
});
|
||||
|
||||
it('preloads session props', async () => {
|
||||
await page.goto(`${base}/preloaded`);
|
||||
|
||||
assert.equal(await title(), 'hello world');
|
||||
|
||||
await start();
|
||||
assert.equal(await title(), 'hello world');
|
||||
|
||||
await page.click('button');
|
||||
assert.equal(await title(), 'changed');
|
||||
});
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
<script>
|
||||
import { getSession } from '@sapper/app';
|
||||
const session = getSession();
|
||||
</script>
|
||||
|
||||
<h1>{$session.title}</h1>
|
||||
Reference in New Issue
Block a user