From: Eduardo San Martin Morote Date: Mon, 25 Oct 2021 12:40:44 +0000 (+0200) Subject: test: add ssr test for hydrate custom refs X-Git-Tag: @pinia/nuxt@0.1.0~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7add4868cd653a365b9264a64d1168a891d1b5d0;p=thirdparty%2Fvuejs%2Fpinia.git test: add ssr test for hydrate custom refs --- diff --git a/packages/pinia/__tests__/ssr.spec.ts b/packages/pinia/__tests__/ssr.spec.ts index 6bd63cbc..f179d280 100644 --- a/packages/pinia/__tests__/ssr.spec.ts +++ b/packages/pinia/__tests__/ssr.spec.ts @@ -2,7 +2,7 @@ * @jest-environment node */ import { createPinia, defineStore } from '../src' -import { Component, createSSRApp, inject, ref, computed } from 'vue' +import { Component, createSSRApp, inject, ref, computed, customRef } from 'vue' import { renderToString, ssrInterpolate } from '@vue/server-renderer' import { useUserStore } from './pinia/stores/user' import { useCartStore } from './pinia/stores/cart' @@ -86,6 +86,40 @@ describe('SSR', () => { expect(await renderToString(app)).toBe(`

Tom: water, water, apples

`) }) + it('hydrates custom refs', async () => { + function useCustomRef() { + let value = 3 + return customRef((track, trigger) => ({ + get() { + track() + return value + }, + set(newValue: number) { + value = newValue + trigger() + }, + })) + } + + const useMainOptions = defineStore('main-options', { + state: () => ({ + customRef: useCustomRef(), + }), + }) + + const { app } = createMyApp({ + ssrRender(ctx: any, push: any, _parent: any) { + push(`

${ssrInterpolate(ctx.store.customRef)}

`) + }, + setup() { + const store = useMainOptions() + return { store } + }, + }) + + expect(await renderToString(app)).toBe(`

3

`) + }) + it('can use a different store', async () => { const { app: a1 } = createMyApp() const { app: a2 } = createMyApp()