cy.intercept('/api/data').as('getData'); cy.visit('/page'); cy.wait('@getData').its('request.method').should(/* your assertion here */);
The request.method property is a string representing the HTTP method. To assert it is exactly 'POST', use should('equal', 'POST'). Other assertions like 'contain' or 'include' are for partial matches or objects, which are not appropriate here.
cy.intercept('/api/user').as('getUser'); cy.visit('/profile'); cy.wait('@getUser').its('request.headers').should('have.property', 'authorization');
The assertion should('have.property', 'authorization') expects the 'authorization' header to exist. If it is missing, Cypress throws an assertion error indicating the property is not found.
cy.intercept('POST', '/api/orders').as('postOrder'); cy.visit('/order'); cy.wait('@postOrder').its('request.body').should('contain', { userId: 123 });
In Cypress, the request.body is often a JSON string, not an object. Using should('contain', { userId: 123 }) fails because it compares an object to a string. You must parse the body or assert on the string content.
Using .then() with expect() allows you to work with the fully resolved response object and write clear assertions. Other options may fail if the response body is not directly accessible or if partial matches cause false positives.
Option D correctly waits for the request, asserts the method, accesses the header with lowercase key, parses the JSON body string, and asserts the 'active' field is true. Other options fail due to incorrect header key casing, missing JSON parsing, or wrong assertion methods.