Home » vue » How can I test the data in the request that is sent during cypress test?

How can I test the data in the request that is sent during cypress test?

Posted by: admin November 26, 2021 Leave a comment

Questions:

I have a Vue application that is using mongodb and flask for the back-end. I am trying to test the code as follows. enter image description here

There is a form as you can see from the image above. When I enter the URL’s, tokens, password, ssh, and project name, and click Create button, I add them to an object and send them to the database in a request.

I want to write these values in Cypress.js (this part is done), and click the create button. After clicking create button I want to test the data that is sent as request. How can I reach the body in the request in cypress?

enter image description here

Answers:

You can use cy.intercept() to look at outbound requests. Request object documentation here.

cy.intercept('/some/url', (req) => {
    // whatever you need to do with the request object
    // for example, validating the request body has a name field
    expect(req.body.name).to.equal('My Body Object Name');

    // req.continue() tells the request to continue!
    req.continue()
});