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

141
Views
modify fixture data in cypress and intercept it

let say I have this setting.json

{ data: { isDark: false } } 

and I intercept it like so

cy.intercept("api/setting", {
    fixture: `setting.json`,
 })

it worked.

But there's no way I want to create one file for one new property in the setting.json or when isDark is true. So how can I change the property values of the setting.json in my test?

I tried

cy.intercept("api/setting", (req) => {
 const settingFixture = await cy.fixture('setting.json')

 req.continue((res) => {
  res.send(settingFixture.map((object)=>({...object, isDark: true}))
 })

 cy.visit('some where')
})

but it doesn't work.

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

0

According to Cypress documentation about fixture command (https://docs.cypress.io/api/commands/fixture#Modifying-fixture-data-before-using-it), I think you can try something like this:

cy.fixture('setting.json').then(settingFixture => {
    
    // Update your JSON object according to your context
    // ...

    // Stub your response with this JSON object updated
    cy.intercept("api/setting", settingFixture)
});


// Navigate to your URL
cy.visit('some where')
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!