question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: FooModule.bar is not a function

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
moltarcommented, May 8, 2019

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.

1reaction
arenddeboercommented, May 13, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found