Skip to content

Commit

Permalink
fix: tweak mapping helper warning message (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Nov 10, 2019
1 parent 9a96720 commit e60bc76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/helpers.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/helpers.spec.js
Expand Up @@ -95,6 +95,7 @@ describe('Helpers', () => {
})

it('mapState (with undefined states)', () => {
spyOn(console, 'error')
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -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)', () => {
Expand Down Expand Up @@ -223,6 +225,7 @@ describe('Helpers', () => {
})

it('mapMutations (with undefined mutations)', () => {
spyOn(console, 'error')
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -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)', () => {
Expand Down Expand Up @@ -389,6 +393,7 @@ describe('Helpers', () => {
})

it('mapGetters (with undefined getters)', () => {
spyOn(console, 'error')
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -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)', () => {
Expand Down Expand Up @@ -524,6 +530,7 @@ describe('Helpers', () => {
})

it('mapActions (with undefined actions)', () => {
spyOn(console, 'error')
const a = jasmine.createSpy()
const store = new Vuex.Store({
modules: {
Expand All @@ -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', () => {
Expand Down

0 comments on commit e60bc76

Please sign in to comment.