How to mock an API route
Answered
Giant panda posted this in #help-forum
Giant pandaOP
I'm started implementing test. But how do I mock the API routes and the DB?
Answered by B33fb0n3
it depends a lot on your testing framework. For example for jest, you have several mock functions: https://jestjs.io/docs/mock-function-api. In general you use
So check your testing library and see what it offers and how to use it
jest.fn() to mock a function.So check your testing library and see what it offers and how to use it
5 Replies
@Giant panda I'm started implementing test. But how do I mock the API routes and the DB?
it depends a lot on your testing framework. For example for jest, you have several mock functions: https://jestjs.io/docs/mock-function-api. In general you use
So check your testing library and see what it offers and how to use it
jest.fn() to mock a function.So check your testing library and see what it offers and how to use it
Answer
@Giant pandasolved?
Giant pandaOP
Yes. I use msw for api and vitest.fn()
Thanks for helping
happy to help