Skip to content

Commit e60bc76

Browse files
authored
fix: tweak mapping helper warning message (#1641)
1 parent 9a96720 commit e60bc76

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/helpers.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { isObject } from './util'
99
export const mapState = normalizeNamespace((namespace, states) => {
1010
const res = {}
1111
if (process.env.NODE_ENV !== 'production' && !isValidMap(states)) {
12-
console.error('[vuex] states parameter must be either an Array/Object')
12+
console.error('[vuex] mapState: mapper parameter must be either an Array or an Object')
1313
}
1414
normalizeMap(states).forEach(({ key, val }) => {
1515
res[key] = function mappedState () {
@@ -42,7 +42,7 @@ export const mapState = normalizeNamespace((namespace, states) => {
4242
export const mapMutations = normalizeNamespace((namespace, mutations) => {
4343
const res = {}
4444
if (process.env.NODE_ENV !== 'production' && !isValidMap(mutations)) {
45-
console.error('[vuex] mutations parameter must be either an Array/Object')
45+
console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object')
4646
}
4747
normalizeMap(mutations).forEach(({ key, val }) => {
4848
res[key] = function mappedMutation (...args) {
@@ -72,7 +72,7 @@ export const mapMutations = normalizeNamespace((namespace, mutations) => {
7272
export const mapGetters = normalizeNamespace((namespace, getters) => {
7373
const res = {}
7474
if (process.env.NODE_ENV !== 'production' && !isValidMap(getters)) {
75-
console.error('[vuex] getters parameter must be either an Array/Object')
75+
console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object')
7676
}
7777
normalizeMap(getters).forEach(({ key, val }) => {
7878
// The namespace has been mutated by normalizeNamespace
@@ -102,7 +102,7 @@ export const mapGetters = normalizeNamespace((namespace, getters) => {
102102
export const mapActions = normalizeNamespace((namespace, actions) => {
103103
const res = {}
104104
if (process.env.NODE_ENV !== 'production' && !isValidMap(actions)) {
105-
console.error('[vuex] actions parameter must be either an Array/Object')
105+
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object')
106106
}
107107
normalizeMap(actions).forEach(({ key, val }) => {
108108
res[key] = function mappedAction (...args) {

test/unit/helpers.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe('Helpers', () => {
9595
})
9696

9797
it('mapState (with undefined states)', () => {
98+
spyOn(console, 'error')
9899
const store = new Vuex.Store({
99100
modules: {
100101
foo: {
@@ -108,6 +109,7 @@ describe('Helpers', () => {
108109
computed: mapState('foo')
109110
})
110111
expect(vm.a).toBeUndefined()
112+
expect(console.error).toHaveBeenCalledWith('[vuex] mapState: mapper parameter must be either an Array or an Object')
111113
})
112114

113115
it('mapMutations (array)', () => {
@@ -223,6 +225,7 @@ describe('Helpers', () => {
223225
})
224226

225227
it('mapMutations (with undefined mutations)', () => {
228+
spyOn(console, 'error')
226229
const store = new Vuex.Store({
227230
modules: {
228231
foo: {
@@ -241,6 +244,7 @@ describe('Helpers', () => {
241244
})
242245
expect(vm.inc).toBeUndefined()
243246
expect(vm.dec).toBeUndefined()
247+
expect(console.error).toHaveBeenCalledWith('[vuex] mapMutations: mapper parameter must be either an Array or an Object')
244248
})
245249

246250
it('mapGetters (array)', () => {
@@ -389,6 +393,7 @@ describe('Helpers', () => {
389393
})
390394

391395
it('mapGetters (with undefined getters)', () => {
396+
spyOn(console, 'error')
392397
const store = new Vuex.Store({
393398
modules: {
394399
foo: {
@@ -411,6 +416,7 @@ describe('Helpers', () => {
411416
})
412417
expect(vm.a).toBeUndefined()
413418
expect(vm.b).toBeUndefined()
419+
expect(console.error).toHaveBeenCalledWith('[vuex] mapGetters: mapper parameter must be either an Array or an Object')
414420
})
415421

416422
it('mapActions (array)', () => {
@@ -524,6 +530,7 @@ describe('Helpers', () => {
524530
})
525531

526532
it('mapActions (with undefined actions)', () => {
533+
spyOn(console, 'error')
527534
const a = jasmine.createSpy()
528535
const store = new Vuex.Store({
529536
modules: {
@@ -541,6 +548,7 @@ describe('Helpers', () => {
541548
})
542549
expect(vm.a).toBeUndefined()
543550
expect(a).not.toHaveBeenCalled()
551+
expect(console.error).toHaveBeenCalledWith('[vuex] mapActions: mapper parameter must be either an Array or an Object')
544552
})
545553

546554
it('createNamespacedHelpers', () => {

0 commit comments

Comments
 (0)