I have trouble with finding a good resource for writing tests for my component which is using Vuex with Typescript and Composition Api in Nuxt2, and how can I do this?
Here is my component codes:
<template>
<div>
<div data-test="open-sidebar" @click="openSidebar">
Sidebar
<hr>
<div v-show="getSidebarStatus">Sidebar data</div>
</div>
</div>
</template>
<script lang="ts">
import { computed, defineComponent, useStore } from '@nuxtjs/composition-api'
export default defineComponent({
name: 'Index',
setup() {
const store = useStore()
const getSidebarStatus = computed((): any => {
return store.getters.getSidebarStatus
})
const openSidebar = (): void => {
store.dispatch('openSidebar')
}
return {
getSidebarStatus,
openSidebar,
}
},
})
</script>
And here is my Vuex module:
export const state = () => ({
isSidebarOpen: false,
})
export const getters = {
getSidebarStatus(state: any) {
return state.isSidebarOpen
},
}
export const mutations = {
openSidebar: (state: any) => (state.isSidebarOpen = true),
}
export const actions = {
openSidebar: (context: any) => context.commit('openSidebar'),
}