'Testing the Network request with cypress

I want to test the network request and assert the requested data with Cypress.

cy.intercept('POST', '*service=jobsSearch*').as('ajaxRequest')

cy.get(selectors.dataComponent('jobs')).find('button').click()

cy.wait('@ajaxRequest')

cy.get('@ajaxRequest').its('request.body').should('contain', 'jobApprenticeshipType=stelle')

cy.get('@ajaxRequest').its('results.body').should('contain', 'mailAlertSearchTerm=Handwerk & Produktion')

I can reach to 'request.body' and assert the 'jobApprenticeshipType=stelle'. However, I can not reach to results.body to assert 'mailAlertSearchTerm=Handwerk & Produktion'. Here is a screenshot of the result:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source