Since aliases are cleared after each test (it
) when using Cypress, it seems subsequent tests needs to execute the same request again and again, while I would prefer to get it only once. This can be verified by replacing beforeEach
with before
, resulting in the second and third test to fail. Of course all assertions could be placed in a single it
, I want each assertion to be reported separately however. Why does Cypress need to reload the resource for each test and how can this be avoided?
/// <reference types="cypress" />
describe('When requesting the resource', () => {
beforeEach(() => {
cy.request('http://startpage.com/').as('response');
});
it('The status code should be 200', () => {
cy.get('@response').its('status').should('be.ok');
});
it('The content type should be text/html', () => {
cy.get('@response').its('headers.content-type').should('include', 'text/html');
});
it('The content should be encoded using UTF-8', () => {
cy.get('@response').its('headers.content-type').should('include', 'charset=utf-8');
});
});