I've got a small VS Code extension in TypeScript that uses the Axios library to make API calls. I've used the recommended Mocha framework to script tests, and am running these locally and via Github Actions.
I've now added c8
to give me code-coverage reports, and wish to improve coverage including the Axios calls. I found this article which recommends adding the jest
framework. However I found that gave type clashes with Mocha, and it seems it's a bad idea to have more than one test framework.
Is there a simple example of how to mock Axios calls with Mocha?
CodePudding user response:
Since you're trying to mock the requests to an API, why not mock the API itself?
https://github.com/nock/nock is a good library that is recommended by mocha that you can try out for your use case.