ユニットスクリプト(TypeScriptおよびvue-class-component
で記述)のユニットテスト時にSinonを使用してAPIコールをスタブしています。単位テストにスタブを追加した後、元のメソッドはまだ呼び出されています(スタブされた値を返さない)。Vue.JSユニットテスト - sinon.stub()を使用しても元のメソッドがまだ呼び出されています。
it('should set the text to bar', async() => {
const stubbedApiResponse =() => {
return 'bar';
};
sinon.stub(MyComponent.prototype, 'getFoo').callsFake(stubbedApiResponse);
let options = {
template: '<div><my-component></my-component></div>',
components: {'my-component': MyComponent},
store: this.store
};
this.vm = new Vue(options).$mount();
Vue.nextTick(() => {
expect(this.vm.$el.querySelector('.text').textContent).toBe('bar'); // Still equals 'foo'
});
});
私はコンポーネントでmounted
に呼び出されたスタブしようとすると、テキストの内容を設定しています方法。どんな助けもありがとう、ありがとう!で
sinon.stub(MyComponent.options.methods, 'getFoo').callsFake(stubbedApiResponse)
:
デバッグのための分のgitリポジトリを提供することはできますか? –