Examples of how to test a Node.js API that makes backend calls to external services.
e.g. browser -> [API -> external service]
There are examples for running tests using Jest, Nock and Playwright.
Playwright alone can't be used as they test at the browser level and so cannot intercept calls node from the backend.
So you're left with two options:
-
Jest mock the module making the backend calls
-
Use a tool like msw to mock the backend calls
At the moment the examples show mocking calls made to the Pokemon API