add session tests

This commit is contained in:
Richard Harris
2019-02-02 15:42:35 -05:00
parent 7fefc59929
commit 11d3da3aed
12 changed files with 46 additions and 14 deletions

View File

@@ -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();

View 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>

View 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>

View File

@@ -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');
});
});

View File

@@ -1,6 +0,0 @@
<script>
import { getSession } from '@sapper/app';
const session = getSession();
</script>
<h1>{$session.title}</h1>