diff --git a/test/nuxt/nuxt-island.test.ts b/test/nuxt/nuxt-island.test.ts index 8c663389b3..7bd50edee3 100644 --- a/test/nuxt/nuxt-island.test.ts +++ b/test/nuxt/nuxt-island.test.ts @@ -98,6 +98,8 @@ describe('runtime server component', () => { return ogFetch(...args) }) vi.stubGlobal('fetch', stubFetch) + + useNuxtApp().payload.data = {} }) afterEach(() => { @@ -140,7 +142,6 @@ describe('runtime server component', () => { }) it('expect to use cached payload', async () => { - useNuxtApp().payload.data = {} const wrapper = await mountSuspended( createServerComponent('CacheTest'), { props: { @@ -174,5 +175,63 @@ describe('runtime server component', () => { expect(fetch).toHaveBeenCalledTimes(2) expect(wrapper.html()).toMatchInlineSnapshot('"
2
"') }) + + it('expect server component to set the response into the payload', async () => { + const wrapper = await mountSuspended( + createServerComponent('CacheTest'), { + props: { + useCache: false, + setCache: true, + props: { + test: 1 + } + } + }) + + expect(fetch).toHaveBeenCalledOnce() + expect(wrapper.html()).toMatchInlineSnapshot('"
1
"') + + expect(Object.keys(useNuxtApp().payload.data).length).toBeGreaterThan(0) + }) + + it('expect server component to NOT set the response into the payload', async () => { + const wrapper = await mountSuspended( + createServerComponent('CacheTest'), { + props: { + useCache: false, + setCache: false, + props: { + test: 1 + } + } + }) + + expect(fetch).toHaveBeenCalledOnce() + expect(wrapper.html()).toMatchInlineSnapshot('"
1
"') + expect(Object.keys(useNuxtApp().payload.data).length).toBe(0) + await wrapper.setProps({ + useCache: false, + setCache: false, + props: { + test: 2 + } + }) + + await flushPromises() + expect(fetch).toHaveBeenCalledTimes(2) + expect(wrapper.html()).toMatchInlineSnapshot('"
2
"') + expect(Object.keys(useNuxtApp().payload.data).length).toBe(0) + await wrapper.setProps({ + useCache: false, + setCache: false, + props: { + test: 2 + } + }) + await flushPromises() + expect(fetch).toHaveBeenCalledTimes(3) + expect(wrapper.html()).toMatchInlineSnapshot('"
3
"') + expect(Object.keys(useNuxtApp().payload.data).length).toBe(0) + }) }) })