Ver código fonte

fix: tweak mapping helper warning message (#1641)

katashin 5 anos atrás
pai
commit
e60bc76154
2 arquivos alterados com 12 adições e 4 exclusões
  1. 4 4
      src/helpers.js
  2. 8 0
      test/unit/helpers.spec.js

+ 4 - 4
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) {

+ 8 - 0
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', () => {