]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: adapt ssr tests
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Nov 2019 15:03:52 +0000 (16:03 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 26 Nov 2019 20:00:07 +0000 (21:00 +0100)
__tests__/ssr/app.spec.ts
__tests__/ssr/app/main.ts
__tests__/tds/store.test-d.ts

index 24b537bc71cc4f7cb939cd361a1dd2c307646149..8c78f9b2e41c13a363588583ca185d908ff9e8e9 100644 (file)
@@ -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(
-      `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 0 x 2 = 0</p> <button>Increment</button></div>"`
+      `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
+    )
+  })
+
+  it('resets the store', async () => {
+    const context = {
+      rendered: () => {},
+    }
+    let app = await renderApp(context)
+
+    // @ts-ignore
+    let html = await renderer.renderToString(app)
+    expect(html).toMatchInlineSnapshot(
+      `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
+    )
+
+    // render again
+    app = await renderApp(context)
+
+    // @ts-ignore
+    html = await renderer.renderToString(app)
+    expect(html).toMatchInlineSnapshot(
+      `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
     )
   })
 })
index f06891f0995506e8c6ef258a604d2a135c0589df..96020e2dd0f3ce4dea2010843515d6f911b02927 100644 (file)
@@ -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),
index a401b3594c208cd816cb658cf85797be38626189..a052ac7f329e9688fbfb31321fb869549ad23124 100644 (file)
@@ -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)