You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// use sinon, chai tool
wrapper = shallowMount(MyComponent, {
methods: { // In vue-test-utils 2.x doesn't support mocking methods while mounting component
callThirdPartyLib: sinon.stub(), // Don't want to call this real method, so stub it.
disableTab: sinon.stub(),
pageScrollTop: sinon.stub()
},
localVue,
store,
});
it('...', () => {
expect(wrapper.vm.callThirdPartyLib).to.have.been.calledOnce;
})
vue-test-utils v2.x
I know we can stub the http request action (axios) in created/mounted lifecycle. This behavior is independent (gloabl function or gloabl instance) from component, so they are easy to stub. But in my scenario, just don't want to call real method (callThirdPartyLib) while mounting component.
import axios from 'axios';
sinon.stub(axios, 'get').resolves({
data: {
// some data here
}
})
Hi,
Sometimes, I really need to mock/stub the component method in created/mounted lifecycle.(like callA method). Have any idea to handle this situation ?
wrapper = shallowMount(MyComponent, { global: { }, methods: { callA: sinon.stub() // <- Mock method } });
The text was updated successfully, but these errors were encountered: