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:
The response has a key of
response
and notresults
. My guess is that your response looks something like...In which case, you'd want to reference it by something like this:
You can see this if you just get the intercept and log the entire thing.