【问题标题】:vuejs namespace getters undefined errorvuejs 命名空间获取器未定义错误
【发布时间】:2017-11-14 22:57:18
【问题描述】:

我在测试命名空间的 getter 时遇到了困难,虽然它可以工作,但我无法成功测试它。

getContextMenuListSelectedState: function (menu) {
  return this.$store.getters['appContext/getContextMenuListSelectedState'](menu)
}

<view-switcher @switchView="setCurrentView" />

setCurrentView: function (obj) {
...
let maintSelected = this.getContextMenuListSelectedState('docsmaint').label === 'maint'
...
}

is throwing an error in test:
'[Vue warn]: Error in event handler for "switchView": "TypeError: this.$store.getters**.appContext/getContextMenuListSelectedState** is not a function"

【问题讨论】:

    标签: vuejs2 vuex


    【解决方案1】:

    这个错误非常具有误导性。我终于能够用假货来存根了。在按照上面提供的重构之后。

     function fakeGetter (menu) {
          return store.state.appContext.contextMenusLists[menu].filter((item) => {
            return item.selected
          })
        }
    
    getContextMenuListSelectedStateSpy = sinon.stub(omsLayout.methods, 'getContextMenuListSelectedState').callsFake(fakeGetter)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多