cypress graphql mock code example
Example 1: cypress graphql request
const query = `{
findUser(username:"hello")
{
id
}
}`;
cy.request(
{
url: 'http://localhost/graphql/',
body: { query },
failOnStatusCode: false
}
).then((res) => {
cy.log(res);
})
Example 2: cypress graphql request example
describe('my page', () => {
beforeEach(function() {
cy.fixture('allCars').as('carsQuery')
})
context('mock & visit', () => {
beforeEach(function() {
cy.mockGraphQL([this.carsQuery])
cy.visit('http://localhost:8080')
})
it('my action', () => {})
})
})