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

116
Visualizações
Moxios not changing stubRequest return data during test

I'm trying to switch responses from the mocked out API during a test, so that I can test a caching option.

So basically what I want is that on the first request I get data1, and on the second request I get data2.

The problem is that on the second request, I am still getting data1, even thought I have told moxios to send back data2.

describe("getDataWithCache", () => {
  it("should fetch data1 on first request and data2 on second request", () => {
    moxios.stubRequest(testUrl, data1)
    const response1 = await makeApiCall(testUrl)
    expect(response1.data.name).toBe(data1.name)

    // This is the line of code where the problem is occurring, because it isn't changing
    // the mock data being returned
    moxios.stubRequest(testUrl, data2)
    const response2 = await makeApiCall(testUrl)
    expect(response2.data.name).toBe(data2.name)
  });
});
about 4 years ago · Juan Pablo Isaza
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