add test utils to include pinia store
This commit is contained in:
22
src/tests/utils.ts
Normal file
22
src/tests/utils.ts
Normal 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
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -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: {
|
||||||
|
|||||||
Reference in New Issue
Block a user