• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

110
Views
Adding an early return to avoid using else and additional nesting

I got the below comment from a developer: " add an early return here to avoid using else and additional nesting". But I have a bit of difficulty with modifying.

Can you please let me know what exactly should I do in this case? Thank you!

failOnStatusCode: false,

    }).then((res) => {


      // Assertion for one by one

      if (res.status != 200) {

        cy.log(JSON.stringify(res));

      } else {

        expect(res.body.id).to.eq(vehicleIdBuyNow);

        expect(res.body.auctionStatus).contains("finished");

        expect(res.body.price).to.be.equal(minPrice);

        expect(res.body.winningBidPlatformId).contains(platformIdBuyNow);

        expect(true).to.be.true;
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The recommendation is to change it to:

.then((res) => {
    if (res.status != 200) {
        cy.log(JSON.stringify(res));
        return; // exit function, no need for an `else` after this
    }
    expect(res.body.id).to.eq(vehicleIdBuyNow);
    expect(res.body.auctionStatus).contains("finished");
    expect(res.body.price).to.be.equal(minPrice);
    expect(res.body.winningBidPlatformId).contains(platformIdBuyNow);
    expect(true).to.be.true;
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error