Skip to content

jest unit-tests fail when referencing vuex store #1895

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

Closed
JaykeOps opened this issue Jul 19, 2018 · 2 comments
Closed

jest unit-tests fail when referencing vuex store #1895

JaykeOps opened this issue Jul 19, 2018 · 2 comments

Comments

@JaykeOps
Copy link

Version

3.0.0-rc.5

Reproduction link

https://github.com/Kusken/vue-cli-rc5-jest-vuex-issue

Steps to reproduce

Steps to reproduce

Project setup

Clone

then run

npm install
npm run test:unit

Alternatively

With @vue/cli rc5

vue create <project-name>

select:

Typescript
Vuex
Jest

After install replace /tests/HelloWorld.spec.ts content with:

import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
import store from "@/store";

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', () => {
    store.state;
  })
})

Run npm run test:unit

What is expected?

Test should pass.

What is actually happening?

Test run results in this error:

TypeError: Cannot read property 'use' of undefined

      2 | import Vuex from 'vuex'
      3 |
    > 4 | Vue.use(Vuex)
        |     ^
      5 |
      6 | export default new Vuex.Store({
      7 |   state: {

      at Object.<anonymous> (src/store.ts:4:5)
      at Object.<anonymous> (tests/unit/HelloWorld.spec.ts:3:1)

By downgrading from "ts-jest": "^23.0.0" to "ts-jest": 22.4.6 the test passes.

P.S - ran in to the bug trying to solve another bug. To triangulate the other bug I created a new vue.js project using @vue/cli-rc5.

@Kocal
Copy link
Contributor

Kocal commented Jul 19, 2018

I had the same problem the other day, I fixed it by updating my tsconfig.json with:

{
  "compilerOptions": {
    "esModuleInterop": true
  }
}

It makes tests work and doesn't break the app.

@art-kc
Copy link

art-kc commented Jun 25, 2022

import * as Vuex from 'vuex'
If anyone still experiencing similar issue with typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants