Skip to content

Commit

Permalink
feat(errors): throw with non-existant modules
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 18, 2018
1 parent fbc7768 commit a5b200f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ exports.Store = class Store {
for (let module of modules) {
if (state[module]) state = state[module]
else {
throw new Error(`[vuex-mock-store] module ${key} not defined in state:`, this.state)
throw new Error(
`[vuex-mock-store] module "${key.slice(0, -1)}" not defined in state:`,
this.state
)
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Store } = require('../src')
const Helper = require('./Helper')
const { mount } = require('@vue/test-utils')
const { mapState } = require('vuex')

describe('Store Mock', () => {
it('copies the state', () => {
Expand Down Expand Up @@ -72,5 +73,20 @@ describe('Store Mock', () => {

expect(wrapper.vm.getter).toBe(1)
})

it('throws with non-defined state', () => {
/** @type {import('@vue/test-utils').Wrapper<Helper>} */
let wrapper = mount(
{
render: () => null,
computed: mapState('nonExistent', ['a']),
},
{ mocks }
)
expect(() => {
// eslint-disable-next-line no-unused-expressions
wrapper.vm.a
}).toThrow(/module "nonExistent" not defined in state/)
})
})
})

0 comments on commit a5b200f

Please sign in to comment.