When testing UI apps, we easily mock the network with cy.intercept
, but until now there was no good way to do a similar thing when testing APIs.
Mockoon is a free and open-source desktop application allowing to quickly mock servers and API.
In the real world, we probably would not be mocking the one service under test, but rather the services it depends on. This is where Mockoon comes in handy.
To showcase it, for local testing all the API endpoints are mocked. Mockoon's network recording feature was used to capture them, and later they were fine tuned. While recording and mocking there are two main things to watch out for:
yarn install
# test the deployment
yarn cy:open-dev
yarn cy:run-dev
# test locally against mock server
# starts mockoon server
yarn mock:server
# alternatively you can run mockoon app locally
# and open the mock file in this repo at ./mockoon/crud-croc.json
yarn cy:open-dev
yarn cy:run-dev
The API we are using https://test-api.k6.io/.
There is a test.http
file in the repo root that can help us get familiar with the API. It uses VsCode REST Client extension to test the api like we would do with Postman.
You find the examples from Mockoon tutorials under the mockoon
folder and the examples.http
file. Just open the file examples.json
with Mockoon and use Vscode Rest Client to reproduce the tutorials.
yarn lint
yarn typecheck
# all the above in parallel
yarn validate