Search code examples
testingautomated-testse2e-testingtestcafecodeceptjs

Catch axios request and provide mock in e2e test


I'm testing external website with separate server. I know that server send api request with axios, like this: GET https://website.com/api/getData Is there a way to catch this request and provide mock data for testing purpose? I don't want to change server-side code, my tests are completely separate.

I've tried axios-mock-adapter but it looks like I have to send a request directly from the test to mock it, but that's not what I'd like to achieve.

I'm using codeceptJS with TestCafe


Solution

  • Yes, you can mock requests sending with the 'axios' library using the RequestMock feature. RequestMock is a low-level feature and allows you to create mocks for any requests.