diff --git a/src/index.js b/src/index.js index 6f493cf..5ae7b7b 100644 --- a/src/index.js +++ b/src/index.js @@ -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 + ) } } diff --git a/test/index.spec.js b/test/index.spec.js index 0150616..f6188ef 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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', () => { @@ -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} */ + 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/) + }) }) })