Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda