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

0

175
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 3 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 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