Marie Drake, Quality Engineering Manager @ Zoopla
/// <reference types="cypress" />
describe('TodoApp', () => {
it('should add a new todo successfully', () => {
cy.visit('/');
cy.get('.new-todo').as('addTodo');
cy.get('@addTodo').type('do lunch and learn about Cypress {enter}');
cy.get('@addTodo').type('have lunch {enter}');
cy.get('.todo-list').find('li').should('have.length', 2);
cy.getFirstTodoItem().should(
'be.equal',
'do lunch and learn about Cypress'
);
});
});
cy.request(url)
cy.request(url, body)
cy.request(method, url)
cy.request(method, url, body)
cy.request(options)
/// <reference types="cypress" />
describe('Todo API', () => {
it('returns a JSON data', () => {
cy.request('/todos')
.its('headers')
.its('content-type')
.should('include', 'application/json');
});
});
Make a GET request to /todos API endpoint
Check its headers
On the header, check its content type
Assert that it returns a JSON data