My request url has multiple query params. I want to mock the response of the external API while writing my tests in Testcafe. I want to mock the data in E2E testing because my data will expire in every 15days. Please suggest some ways to handle mocking the request with query param. I am able to mock the request not having any query param and I am using Request Hooks for that.
Asked
Active
Viewed 2,579 times
1 Answers
2
There shouldn't be a difference between a mocking response from URL with parameters and without them. You can mock a response by using RequestMock
API:
...
const getDataMock = RequestMock()
.onRequestTo(/.*getData\?param=param_1/)
.respond((req, res) => {
res.setBody({...});
});
...
If this doesn't work for you, please provide us with the code where you define RequestMock
or RequestHook
.

aleks-pro
- 1,659
- 4
- 12
-
Thanks :) For some reason that was not working but I tried again after seeing your comments and it worked. – dojo Jun 16 '20 at 18:31