Vuex-module-decorators: TypeError: FooModule.bar is not a function

Created on 23 Feb 2019  路  6Comments  路  Source: championswimmer/vuex-module-decorators

Give this module:

import { Module, Mutation, VuexModule, Action } from 'vuex-module-decorators'

@Module({name: 'foo'})
export class FooModule extends VuexModule{
   arr: string[]  = []
   bar( x: string): string[]{
      return this.arr.filter(s => s === x)
   }
}

Testing with Jest:

import {getModule} from 'vuex-module-decorators'
import {store} from "../index"
import {FooModule} from "../modules/foo-module"

describe('FooModule', () => {
    it('bar', (done) => {
        const fooModule = getModule(FooModule, store)
        expect(fooModule.bar('a')).toEqual([])
    })
})

results in: TypeError: fooModule.bar is not a function

Most helpful comment

Have you tried something like: get bar() { return (x: string) => ...?

This does work indeed. But would be great to support actual class methods, if possible.

All 6 comments

I guess the question is this: can vuex-module-decorators support Vuex's parameterized (method-style) getters?

https://vuex.vuejs.org/guide/getters.html

?

Have you tried something like: get bar() { return (x: string) => ...?

Have you tried something like: get bar() { return (x: string) => ...?

This does work indeed. But would be great to support actual class methods, if possible.

I have the same question, is this closed because it is a feature request ? The problem with getters is indeed the inability to pass a parameter.

also waiting for a solution or at least further informations. Duplicated issues or something?

EDIT: Searching the issues the workaround suggested is using lambdas.
https://github.com/championswimmer/vuex-module-decorators/issues/64

Was this page helpful?
0 / 5 - 0 ratings