From 5f3b36c447cc02b3ebd3370dcc781eda7433763d Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 25 Nov 2019 16:03:52 +0100 Subject: [PATCH] test: adapt ssr tests --- __tests__/ssr/app.spec.ts | 26 +++++++++++++++++++++++--- __tests__/ssr/app/main.ts | 2 ++ __tests__/tds/store.test-d.ts | 13 ++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/__tests__/ssr/app.spec.ts b/__tests__/ssr/app.spec.ts index 24b537bc..8c78f9b2 100644 --- a/__tests__/ssr/app.spec.ts +++ b/__tests__/ssr/app.spec.ts @@ -9,13 +9,33 @@ describe('classic vue app', () => { rendered: () => {}, } const app = await renderApp(context) - // TODO: is this really here? - context.rendered() // @ts-ignore const html = await renderer.renderToString(app) expect(html).toMatchInlineSnapshot( - `"

Hi anon

Count: 0 x 2 = 0

"` + `"

Hi anon

Count: 1 x 2 = 2

"` + ) + }) + + it('resets the store', async () => { + const context = { + rendered: () => {}, + } + let app = await renderApp(context) + + // @ts-ignore + let html = await renderer.renderToString(app) + expect(html).toMatchInlineSnapshot( + `"

Hi anon

Count: 1 x 2 = 2

"` + ) + + // render again + app = await renderApp(context) + + // @ts-ignore + html = await renderer.renderToString(app) + expect(html).toMatchInlineSnapshot( + `"

Hi anon

Count: 1 x 2 = 2

"` ) }) }) diff --git a/__tests__/ssr/app/main.ts b/__tests__/ssr/app/main.ts index f06891f0..96020e2d 100644 --- a/__tests__/ssr/app/main.ts +++ b/__tests__/ssr/app/main.ts @@ -11,6 +11,8 @@ export function createApp() { clear() const store = useStore() + store.state.counter++ + // create the app instance, injecting both the router and the store const app = new Vue({ render: h => h(App), diff --git a/__tests__/tds/store.test-d.ts b/__tests__/tds/store.test-d.ts index a401b359..a052ac7f 100644 --- a/__tests__/tds/store.test-d.ts +++ b/__tests__/tds/store.test-d.ts @@ -1,9 +1,16 @@ import { createStore } from '../../src' import { expectType, expectError } from 'tsd' -const store = createStore('name', () => ({ a: 'on' as 'on' | 'off' }), { - upper: state => state.a.toUpperCase(), -}) +const store = createStore( + 'name', + () => ({ a: 'on' as 'on' | 'off' }), + { + upper: state => state.a.toUpperCase(), + }, + { + doStuff(store, n: number, a: 'on' | 'off') {}, + } +) expectType<{ a: 'on' | 'off' }>(store.state) -- 2.47.2