Skip to content

Mocking getters using TypeScript and Composition API #1835

Closed Answered by th1nkgr33n
felixzapata asked this question in Help and Questions
Discussion options

You must be logged in to vote

I think the initialState property is really just for the "state" so in your case "current".

The Getter (in your case the computed) needs to be overwritten inside the tests itself like this.
There is a small hint inside the docs: https://pinia.vuejs.org/cookbook/testing.html#mocking-getters

import { afterEach, beforeEach, describe, test, vi } from 'vitest'
import { getActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing';
import { useCustomStore} from '~/store/custom.store'
import { cleanup, render } from '@testing-library/vue'


describe('Some Test Suite', () => {
  let customStore: any
  let testingPinia: any

  beforeAll(() => {
    testingPinia = createTestingP…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by felixzapata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants