Open bissolli opened 3 years ago
What I did is move the creation of the mock inside the Template definition, an use this.$axios
const Template = (_: Args, { argTypes }: StoryContext) => ({
props: Object.keys(argTypes),
created() {
const mockAxios = new MockAxiosAdapter(this.$axios);
mockAxios.onGet(`/whatever-api-endpoint/${mockPayment.id}`).reply(200, mockPayment);
},
components: { MyComponent },
template: `<my-component />`,
});
Hey guys, I was wondering how can I mock the axios instance of this module on Storybook. Has anyone accomplished it?
On a plain Vue project usually I mock the axios instance before mounting the component like this:
My main problem is how to get the axios instance from the package to be able to mock it here
const mockAxios = new MockAxiosAdapter(axios)
Any clue?! I am very curious to see how you guys mock HTTP requests on your stories as well - I am open to know new approaches =)
NOTE: I tried mocking in the
setup
method of myTemplate
, but is doesn't work well when you haveuseAsync
oruseFetch
.