vuex-persist: Cannot run unit tests

I am attempting to use vue-test-utils and jest to run some unit tests on my vuex actions. I am running into the error below. Any ideas on how I can get this resolved?

 FAIL  test/unit/specs/masternode/Provision.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property '_config' of undefined

    
      
      at new VuexPersistence (node_modules/vuex-persist/dist/index.js:133:44)
      at Object.<anonymous> (src/store/index.js:60:17)
      at Object.<anonymous> (src/contracts/MNProposedMarket.js:19:14)
      at Object.<anonymous> (src/store/modules/app/actions.js:35:25)
      at Object.<anonymous> (src/store/modules/app/index.js:7:16)
      at Object.<anonymous> (src/store/modules/index.js:7:12)
      at Object.<anonymous> (test/unit/specs/masternode/Provision.spec.js:27:16)

Here is my spec so far:

describe('AppActions', () => {
  const vuexLocal = new VuexPersist({
    storage: window.localStorage,
    modules: ['app', 'masternode', 'marketplace'],
  })
  let store

  beforeEach(() => {
    store = new VuexStore ({
      plugins: [vuexLocal.plugin]
    })
  })
})

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Sorry I had been really swamped by work. I’ll fix this, this week.

On Mon 23 Apr, 2018, 5:34 PM SkyzohKey, notifications@github.com wrote:

Same issue here, we are using vuex-persist to store some credentials on the sessionStorage for a company internal tool but it seems that it is currently not possible to run tests. Same error as above.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/championswimmer/vuex-persist/issues/41#issuecomment-383551443, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQ_ynZHQjjp964TwYKIglWz4HOYnz-cks5trcNpgaJpZM4S3gc9 .

Thanks @championswimmer , I’ve tried v1.1.6 … original error disappeared, but a new one came up :

 FAIL  test/unit/specs/ProjectSwitch.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getItem' of undefined

      23 | }
      24 | 
    > 25 | export default new Vuex.Store({
      26 |   state,
      27 |   mutations,
      28 |   actions,
      
      at VuexPersistence.restoreState (node_modules/vuex-persist/dist/index.js:201:43)
      at VuexPersistence.plugin (node_modules/vuex-persist/dist/index.js:225:40)
      at node_modules/vuex/dist/vuex.common.js:353:46
          at Array.forEach (<anonymous>)
      at new Store (node_modules/vuex/dist/vuex.common.js:353:11)
      at Object.<anonymous> (src/store/index.js:25:1)
      at Object.<anonymous> (test/unit/specs/ProjectSwitch.spec.js:7:14)