我試圖爲我的應用程序在Vue和vue-cli中使用webpack模板創建一個單元測試。我如何在Vue中用sinon窺探或模擬方法?
我閱讀Vue文檔,vue-loader,vue-cli和vue-template/webpack(更多!)。當我嘗試爲我的組件進行單元測試時,我使用它。
const Constructor = Vue.extend(MovieList)
vm = new Constructor({
propsData: {
criteria
},
methods: {
fetch: sandbox.spy()
}
}).$mount()
和測試這樣的:
expect(vm.fetch).to.be.called
但我得到這個錯誤:
✗ should be called fetch
TypeError: { [Function: boundFn] _length: 0 } is not a spy or a call to a spy! at assertCanWorkWith (/home/jmanuelrosa/Developer/personales/vue-course/movues/node_modules/sinon-chai/lib/sinon-chai.js:43:19) at Assertion. (/home/jmanuelrosa/Developer/personales/vue-course/movues/node_modules/sinon-chai/lib/sinon-chai.js:70:13) at Assertion.addProperty (/home/jmanuelrosa/Developer/personales/vue-course/movues/node_modules/chai/chai.js:4240:29) at Context. (webpack:///test/unit/specs/MovieList.spec.js:74:39 <- index.js:14910:39)