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

336
Views
Cypress: cómo espiar un método llamado al hacer clic en un botón

Estoy usando Vue3 + Vite + Cypress. Uso de la sintaxis SFC script setup Vue3. tengo un componente:

 <template> <div> <button data-cy="testBtn" @click="btnClick()"> Click </button> </div> </template> <script setup lang="ts"> function btnClick():void { console.log('clicked'); } </script>

¿Cómo puedo espiar btnClick para poder afirmar que ha sido llamado cuando hago cy.get('[data-cy="testBtn"]').click(); ?
Yo he tratado:

 describe('Test', () => { it.only(`Test`, () => { mount(TestComponent, { props: { device: TestComponent } }); cy.vue().then((wrapper) => { const test = cy.spy(wrapper.vm, 'btnClick'); cy.get('[data-cy="testBtn"]').click(); expect(test).to.be.called; }); }); });

pero aparece un error Attempted to wrap undefined property btnClick as function

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

0

Parece un error en cy.spy() cuando se usa con la prueba de componentes.

Este espía "manual" me funcionó

 it.only('', () => { mount(TestComponent) .then(() => { // wait for mount to complete // spy on click handler let called; const original = Cypress.vueWrapper.vm.btnClick Cypress.vueWrapper.vm.btnClick = () => { called = true original() } cy.get('[data-cy="testBtn"]').click() .then(() => expect(called).to.eq(true)) }) });
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!