Cypress
-
Add a custom command
mockServerRequestin support files, see example mock-server-request.js. -
Use the custom command to define mocks:
it('shows list of users', () => {// set up server-side mockcy.mockServerRequest('https://jsonplaceholder.typicode.com/users', {body: [{ id: 1, name: 'John Smith' }],});// navigate to the pagecy.visit('/');// assert page content according to mockcy.get('li').first().should('have.text', 'John Smith');});