add test utils to include pinia store

This commit is contained in:
Julien Calixte
2023-04-09 10:20:28 +02:00
parent ee6941bf76
commit e6e7db466a
2 changed files with 24 additions and 2 deletions

22
src/tests/utils.ts Normal file
View File

@@ -0,0 +1,22 @@
import { createTaskFixture } from '@/use-cases/task/models/task.fixture'
import type { TaskStoreState } from '@/use-cases/task/stores/useTask.store'
import { createTestingPinia } from '@pinia/testing'
export interface InitialState {
'task-store': TaskStoreState
}
const initialState = {
'task-store': { tasks: [createTaskFixture(), createTaskFixture()] }
}
export const withStore = (partialState?: TaskStoreState) => ({
global: {
plugins: [
createTestingPinia({
...partialState,
initialState
})
]
}
})

View File

@@ -1,12 +1,12 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import type { Taskable } from '../interfaces/taskable' import type { Taskable } from '../interfaces/taskable'
interface State { export interface TaskStoreState {
tasks: Taskable[] tasks: Taskable[]
} }
export const useTaskStore = defineStore('task-store', { export const useTaskStore = defineStore('task-store', {
state: (): State => ({ state: (): TaskStoreState => ({
tasks: [] tasks: []
}), }),
actions: { actions: {