Skip to content

I can't get Gettters mocking to work.... #1255

Discussion options

You must be logged in to vote
  • You don't need getters that return state, just use the state directly and remove the getters
  • state in getters is just state, not getters, so it should bestate.firstName not state.getFirstName
  • You don't need actions to mutate the state, just change it directly. You can remove setFirstName
  • Most of the time, you don't use the testing pinia for unit testing stores, you use it to unit test components that use stores

Example:

import { createTestingPinia } from '@pinia/testing';
import { setActivePinia, createPinia, defineStore } from 'pinia';

const useCounter = defineStore('newStore', {
  state: () => ({ firstName: 'Tom', lastName: 'Hanks' }),
  getters: {
    getFullName(state) {
      return 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fermaud
Comment options

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants