From e60bc76154bb05c12b24342617b946d9a6e2f476 Mon Sep 17 00:00:00 2001 From: katashin Date: Sun, 10 Nov 2019 23:09:25 +0800 Subject: [PATCH] fix: tweak mapping helper warning message (#1641) --- src/helpers.js | 8 ++++---- test/unit/helpers.spec.js | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 8f97840ff..722a9ce63 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -9,7 +9,7 @@ import { isObject } from './util' export const mapState = normalizeNamespace((namespace, states) => { const res = {} if (process.env.NODE_ENV !== 'production' && !isValidMap(states)) { - console.error('[vuex] states parameter must be either an Array/Object') + console.error('[vuex] mapState: mapper parameter must be either an Array or an Object') } normalizeMap(states).forEach(({ key, val }) => { res[key] = function mappedState () { @@ -42,7 +42,7 @@ export const mapState = normalizeNamespace((namespace, states) => { export const mapMutations = normalizeNamespace((namespace, mutations) => { const res = {} if (process.env.NODE_ENV !== 'production' && !isValidMap(mutations)) { - console.error('[vuex] mutations parameter must be either an Array/Object') + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object') } normalizeMap(mutations).forEach(({ key, val }) => { res[key] = function mappedMutation (...args) { @@ -72,7 +72,7 @@ export const mapMutations = normalizeNamespace((namespace, mutations) => { export const mapGetters = normalizeNamespace((namespace, getters) => { const res = {} if (process.env.NODE_ENV !== 'production' && !isValidMap(getters)) { - console.error('[vuex] getters parameter must be either an Array/Object') + console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object') } normalizeMap(getters).forEach(({ key, val }) => { // The namespace has been mutated by normalizeNamespace @@ -102,7 +102,7 @@ export const mapGetters = normalizeNamespace((namespace, getters) => { export const mapActions = normalizeNamespace((namespace, actions) => { const res = {} if (process.env.NODE_ENV !== 'production' && !isValidMap(actions)) { - console.error('[vuex] actions parameter must be either an Array/Object') + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object') } normalizeMap(actions).forEach(({ key, val }) => { res[key] = function mappedAction (...args) { diff --git a/test/unit/helpers.spec.js b/test/unit/helpers.spec.js index f1689f622..e3d5ee44c 100644 --- a/test/unit/helpers.spec.js +++ b/test/unit/helpers.spec.js @@ -95,6 +95,7 @@ describe('Helpers', () => { }) it('mapState (with undefined states)', () => { + spyOn(console, 'error') const store = new Vuex.Store({ modules: { foo: { @@ -108,6 +109,7 @@ describe('Helpers', () => { computed: mapState('foo') }) expect(vm.a).toBeUndefined() + expect(console.error).toHaveBeenCalledWith('[vuex] mapState: mapper parameter must be either an Array or an Object') }) it('mapMutations (array)', () => { @@ -223,6 +225,7 @@ describe('Helpers', () => { }) it('mapMutations (with undefined mutations)', () => { + spyOn(console, 'error') const store = new Vuex.Store({ modules: { foo: { @@ -241,6 +244,7 @@ describe('Helpers', () => { }) expect(vm.inc).toBeUndefined() expect(vm.dec).toBeUndefined() + expect(console.error).toHaveBeenCalledWith('[vuex] mapMutations: mapper parameter must be either an Array or an Object') }) it('mapGetters (array)', () => { @@ -389,6 +393,7 @@ describe('Helpers', () => { }) it('mapGetters (with undefined getters)', () => { + spyOn(console, 'error') const store = new Vuex.Store({ modules: { foo: { @@ -411,6 +416,7 @@ describe('Helpers', () => { }) expect(vm.a).toBeUndefined() expect(vm.b).toBeUndefined() + expect(console.error).toHaveBeenCalledWith('[vuex] mapGetters: mapper parameter must be either an Array or an Object') }) it('mapActions (array)', () => { @@ -524,6 +530,7 @@ describe('Helpers', () => { }) it('mapActions (with undefined actions)', () => { + spyOn(console, 'error') const a = jasmine.createSpy() const store = new Vuex.Store({ modules: { @@ -541,6 +548,7 @@ describe('Helpers', () => { }) expect(vm.a).toBeUndefined() expect(a).not.toHaveBeenCalled() + expect(console.error).toHaveBeenCalledWith('[vuex] mapActions: mapper parameter must be either an Array or an Object') }) it('createNamespacedHelpers', () => {