Documentation
REFERENCE
RequestMock Class
A request mocker that intercepts requests to a web resource and emulates the response.
Use the RequestMock constructor to create a mocker.
Call the onRequestTo and respond methods in a chain to specify mock responses for every handled request.
To use the mocker during tests, attach it to a test or fixture.
import { RequestMock } from 'testcafe';
var mock = RequestMock()
.onRequestTo('https://api.mycorp.com/users/id/135865')
.respond({
name: 'John Hearts',
position: 'CTO'
})
.onRequestTo(/internal.mycorp.com/)
.respond(null, 404);
fixture `My fixture`
.page `https://mycorp.com`
.requestHooks(mock);
test('My test', async t => { /* ... */ });