Skip to content

Instantly share code, notes, and snippets.

@gma
Created December 2, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gma/bef195bb5433df284b4f75bec38c9cc1 to your computer and use it in GitHub Desktop.
Save gma/bef195bb5433df284b4f75bec38c9cc1 to your computer and use it in GitHub Desktop.
Stubbing XHR in Cypress
import axios from 'axios';
describe('Cypress', function() {
it('stubs a GET request', function() {
cy.server();
const endpoint = 'http://my-api-host/path';
cy.route('GET', endpoint, {
attr: [{ thing: 1234 }]
});
axios.get(endpoint).then(response => {
console.log(response);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment