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

131
Visualizações
Stuck on stubbing the location.href

I'm trying to stub location.href from this reference: https://medium.com/cypress-io-thailand/understand-stub-spy-apis-that-will-make-your-test-better-than-ever-on-cypress-io-797cb9eb205a and found out the stub properties used is already deprecated so I do workaround with the new connotations:

stub(obj, 'meth').callsFake(fn)

After several tests, I got stuck because the stub seems not called properly. Here is my code look like:

const winSetLocationHrefStub = (url) => {    
expect(url).to.eq('setLocationHref')};


cy.window().then((win) => {
cy.stub(win,'setLocationHref').callsFake(winSetLocationHrefStub)});

cy.get(.button).click()

I knew that to stub a location.href property, we need to create fn on the main.js file, so here's the main.js code looks like

export const setLocationHref = (url) => {
    window.location.href = url; };

const WhatsAppEnquireButton = (props) => {
    useEffect(() => {
          window.setLocationHref = setLocationHref;
    }, []);
    const handleOnClick = (e) => {
          setLocationHref(formatWhatsAppUrl(foo, bar));

How to make it correctly stub the button I clicked?

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