lundi 30 août 2021

Cypress | Chai assertions executes outside if else condition. Assertions are mentioned inside if condition

I am writing a cypress custom command, which fetches a json response from an API end point. I am writing some assertions on the json response. However, I have a if-else condition to be executed. See below.

cy.getReportJson('84b636f4-c8f0-4aa4-bdeb-15abf811d432',user).then(report=> {
                    
                    if(services.request_criminal_record_check.include){
                        console.log('inside if')
                        cy.wait(30000)
                        expect(report.report_summary.rcmp_result.status).equal(data.expected_result.rcmp_result.status)
                        expect(report.report_summary.rcmp_result.overall_score).equal(data.expected_result.rcmp_result.overall_score)
                        expect(report.report_summary.rcmp_result.result).equal(data.expected_result.rcmp_result.result)
                    }
                })

When I run this code in a spec file, the Output I get is as follows.

enter image description here

As you can see, the assertions are running, before the wait command is triggered. I want cypress to wait for 30 seconds, so that the back-end runs its magic and generates a report and after 30 seconds, i wanna assert on the report json. Even the console.log is printed after the assertions are executed.

Is this something related to the async nature of Cypress?

Aucun commentaire:

Enregistrer un commentaire