From a5b200f8a6c46f7a4a4124cfe91afdbefc1d0f85 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 18 Sep 2018 23:31:23 +0200 Subject: [PATCH] feat(errors): throw with non-existant modules --- src/index.js | 5 ++++- test/index.spec.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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/) + }) }) })