TypeError: FooModule.bar is not a function
See original GitHub issueGive 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >Ts-mock-imports NPM
mockClass<fooModule.Foo, typeof fooModule>(fooModule, 'Foo'); // Will result in a TS Error as Bar is not exported by Foo const mockManager = ImportMock.
Read more >Why is Foo not a function when I defined it? - Stack Overflow
Your bar function is declaring a new foo variable (which hides the global one ... bar(); //returns Uncaught TypeError: foo is not a...
Read more >ts-mock-imports | Yarn - Package Manager
mockClass(fooModule, 'Foo'); // Will throw a type error if bar() does not exist on Foo fooManager.mock('bar'); // new Foo().bar() will return undefined.
Read more >Documentation - TypeScript 4.4
fooModule.foo();. This is not the way exported functions in ECMAScript are supposed to work when we call them.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.