Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

66
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?

7 months 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');
});
7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.