Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda