Skip to content

Commit

Permalink
chore: add store test
Browse files Browse the repository at this point in the history
  • Loading branch information
wattanx committed Oct 11, 2023
1 parent 7d32788 commit f473a80
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineNuxtConfig({
})
}
],
plugins: ['~/plugins/setup.js'],
plugins: ['~/plugins/setup.js', '~/plugins/store.js'],
nitro: {
routeRules: {
'/route-rules/spa': { ssr: false }
Expand Down
11 changes: 11 additions & 0 deletions playground/pages/store.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
const { $store } = useNuxtApp()
const test = computed(() => $store.state.test)
</script>

<template>
<div>
<p>state is: {{ test }}</p>
</div>
</template>
5 changes: 5 additions & 0 deletions playground/plugins/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default defineNuxtPlugin(() => {
const { $store } = useNuxtApp()

$store.commit('setTest', '✅')
})
6 changes: 6 additions & 0 deletions playground/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export const actions = {
state.test = '✅'
}
}

export const mutations = {
setTest (state, value) {
state.test = value
}
}
12 changes: 12 additions & 0 deletions test/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ describe('legacy capi', () => {
expect(html).toMatch(/([\s\S]*✅){11}/)
await expectNoClientErrors('/legacy-capi')
})

it('should be changed store.state', async () => {
const html = await $fetch('/legacy-capi')
expect(html).toContain('<tr><td><b>useStore</b></td><td> ✅</td></tr>')
})
})

describe('errors', () => {
Expand Down Expand Up @@ -191,6 +196,13 @@ describe('middleware', () => {
})
})

describe('store', () => {
it('should be able to access $store in plugins', async () => {
const html = await $fetch('/store')
expect(html).toContain('state is: ✅')
})
})

describe('nitro plugins', () => {
it('should prepend a node to the rendered template', async () => {
const html = await $fetch('/nitro/template-plugin')
Expand Down

0 comments on commit f473a80

Please sign in to comment.