Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property '_modulesNamespaceMap' of undefined #1330

Closed
Prior99 opened this issue Jul 2, 2018 · 9 comments
Closed

TypeError: Cannot read property '_modulesNamespaceMap' of undefined #1330

Prior99 opened this issue Jul 2, 2018 · 9 comments

Comments

@Prior99
Copy link

Prior99 commented Jul 2, 2018

Versions

  • vuex: 3.0.1
  • vue-test-utils: 1.0.0-beta.18
  • vue-jest: 2.6.0
  • vue-template-compiler: 2.5.16
  • vue: 2.5.16
  • jest: 23.2.0

Reproduction link

https://github.com/Prior99/vuex-crash-reproduce

Steps to reproduce

  1. Clone reproduction repository
  2. Install dependencies using yarn
  3. Run the unit tests using yarn test

What is expected?

The unit tests should pass.

What is actually happening?

The unit tests fail with:

    TypeError: Cannot read property '_modulesNamespaceMap' of undefined
        at getModuleByNamespace (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vuex/dist/vuex.common.js:914:22)
        at VueComponent.mappedGetter (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vuex/dist/vuex.common.js:847:25)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at Watcher.evaluate (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3247:21)
        at Proxy.computedGetter (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3505:17)
        at Proxy.render (/home/prior/repositories/kn/jest-vue-reproduce/src/some-component.vue:726:50)
        at VueComponent.Vue._render (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4542:22)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:21)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at init (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4135:13)
        at createComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5606:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5553:9)
        at createChildren (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5680:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5582:9)
        at VueComponent.patch [as __patch__] (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:6089:7)
        at VueComponent.Vue._update (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2658:19)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:10)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at init (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4135:13)
        at createComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5606:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5553:9)
        at VueComponent.patch [as __patch__] (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:6089:7)
        at VueComponent.Vue._update (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2658:19)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:10)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at Object.mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/@vue/test-utils/dist/vue-test-utils.js:5940:21)
        at Object.<anonymous> (/home/prior/repositories/kn/jest-vue-reproduce/src/__tests__/test-something.ts:19:21)
        at Object.asyncFn (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/jasmine_async.js:108:37)
        at resolve (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:56:12)
        at new Promise (<anonymous>)
        at mapper (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:43:19)
        at promise.then (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:87:41)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)

When changing the store module not to use namespaces by removing the

                namespaced: true,

in both src/__tests__/test-something.ts and src/store.ts and changing the line

        ...mapGetters("myModule", ["getContent"]),

to

        ...mapGetters(["getContent"]),

in src/some-component.vue the error changes to:

    TypeError: Cannot read property 'getters' of undefined
        at VueComponent.mappedGetter (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vuex/dist/vuex.common.js:850:73)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at Watcher.evaluate (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3247:21)
        at Proxy.computedGetter (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3505:17)
        at Proxy.render (/home/prior/repositories/kn/jest-vue-reproduce/src/some-component.vue:726:50)
        at VueComponent.Vue._render (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4542:22)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:21)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at init (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4135:13)
        at createComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5606:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5553:9)
        at createChildren (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5680:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5582:9)
        at VueComponent.patch [as __patch__] (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:6089:7)
        at VueComponent.Vue._update (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2658:19)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:10)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at init (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:4135:13)
        at createComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5606:9)
        at createElm (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:5553:9)
        at VueComponent.patch [as __patch__] (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:6089:7)
        at VueComponent.Vue._update (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2658:19)
        at VueComponent.updateComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2786:10)
        at Watcher.get (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3140:25)
        at new Watcher (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:3129:12)
        at mountComponent (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:2793:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/vue/dist/vue.runtime.common.js:7997:10)
        at Object.mount (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/@vue/test-utils/dist/vue-test-utils.js:5940:21)
        at Object.<anonymous> (/home/prior/repositories/kn/jest-vue-reproduce/src/__tests__/test-something.ts:19:21)
        at Object.asyncFn (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/jasmine_async.js:108:37)
        at resolve (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:56:12)
        at new Promise (<anonymous>)
        at mapper (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:43:19)
        at promise.then (/home/prior/repositories/kn/jest-vue-reproduce/node_modules/jest-jasmine2/build/queue_runner.js:87:41)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)

Please note that the unit test is not failing with these errors. They are logged from inside vue.runtime.common.js.
The actual error with which the unit tests fail is:

    TypeError: Cannot read property 'getters' of undefined

      at VueComponent.mappedGetter (node_modules/vuex/dist/vuex.common.js:850:73)
      at Proxy.render (src/some-component.vue:726:50)
      at Object.<anonymous> (src/__tests__/test-something.ts:19:21)

Hints

  • When removing Vue.extend in src/some-component.vue the failing test passes.
  • The error only occurs when the SomeComponent component is used inside a parent component, hence the test in src/__tests__/test-some-component.ts test is passing.
  • This also happens with version 2.x.x of vuex and older versions of jest and vue.
  • This issue also happens when not using local vue.

This issue might be related to other issues across the web:

@Prior99
Copy link
Author

Prior99 commented Jul 2, 2018

We did some further investigations and came to the conclusion that the beforeCreate hook with which Vuex registers the $store property on all components is not called early enough. I created another issue in vue: vue#8441. This might also solve this issue.

@ktsn
Copy link
Member

ktsn commented Jul 2, 2018

This is because the component in the actual source code and the instance in the test code reference different Vue constructor. We cannot do anything for this in Vuex side...

@ktsn ktsn closed this as completed Jul 2, 2018
@Prior99
Copy link
Author

Prior99 commented Jul 3, 2018

@ktsn Thanks for your quick response and very helpful answer.

@jo0ger
Copy link

jo0ger commented Aug 21, 2018

so, how to resolve this problem?

@ktsn
Copy link
Member

ktsn commented Aug 21, 2018

This is already fixed on vue-test-utils.

@MatthewBooth
Copy link

I'm still getting this issue with the latest verison of test utils (at time of writing).

@Sean-Spark
Copy link

This is already fixed on vue-test-utils.

could you give us more detail about it

@flozero
Copy link

flozero commented Feb 27, 2019

It is not fixed because no example for it

@ktsn
Copy link
Member

ktsn commented Feb 27, 2019

  1. Use the latest vue-test-utils.
  2. Make sure you inject localVue in your mount option. https://vue-test-utils.vuejs.org/api/options.html#localvue

Please consider to use forum or chat before asking your question in already closed issue as it is not a support forum. The maintainers tend to not respond as it is marked as solved already. If it still happens on your side by other cause, please open a new issue.

@vuejs vuejs locked as resolved and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants