I am using Sinon to stub API calls when unit testing my components (written with TypeScript and vue-class-component
). After adding the stub to the unit test, the original method is still being called (not returning the stubbed value).
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'
});
});
The method that I am attempting to stub is called on mounted
in the component and sets the text content. Any help would be appreciated, thanks!