Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Cypress and Cucumber reset the requests in Next Js

I am using in my next js application cypress to test a page. I need to test 2 scenarios: 1. Success and 2. Bad when user receives an error.

Before(() => {
  return void cy.server()
});

// first scenario
Given('the user access app', () => {
  ...
});

And('the user make request', () => {
  cy.route('GET', `${api}/cars`, 'fixture:good').as('goodRequest');
});

Then('the user should see good answer', () => {
  cy.get('[data-cy=ok]').should('exist')
})

//second scenario
Given('the user access app', () => {
  ...
});

And('the user make request', () => {
  cy.route('GET', `${api}/cars`, 'fixture:bad').as('badRequest');
});

Then('the user should see bad answer', () => {
  cy.get('[data-cy=bad]').should('exist')
})

The first test pass, but when the second starts, i anyway get the previous response from the first request and get on the page the good response and test fails because the bad text does not appear on the page.
Is there a solution to reset the response after each test or something like this? How to solve the issue?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Don't use cy.route() to send requests, use cy.request().

And('the user make request', () => {
  cy.request('GET', `${api}/cars`).as('goodRequest');
});
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!