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

223
Views
Broma: ¿cómo simular una función anidada como document.head.querySelector?

Tengo una configuración de laravel vue, ¿cómo puedo burlarme de document.head.querySelector con broma? Tengo que importar un archivo en jest-setup.js para simular otras funciones y bibliotecas, pero también tiene este código que necesita una función de espionaje en document.head.querySelector:

 let token = document.head.querySelector('meta[name="csrf-token"]'); if (token) { axios.headers.common['X-CSRF-TOKEN'] = token.content; } else { console.error('CSRF token not found'); }

Quiero burlarme de document.head.querySelector a algo como

 jest.spyOn(document, 'querySelector').mockImplementation((selector) => { switch (selector) { case '.meta[name="csrf-token"]': return 'test-token'; } });

pero esto no funciona porque no me estoy burlando del head.querySelector que no sé cómo.

about 4 years ago · Juan Pablo Isaza
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!