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

109
Views
Prueba unitaria, cómo usar Sinon para simular una función y afirmar que ha sido llamada

Soy nuevo en UnitTest. Tengo una función setData y trato de escribir una prueba con mocha chai. Intento burlarme de la función function2.setCode que requiere de otro módulo y afirmar que se ha llamado cuando se prueba la función setData. Pero tiene un error al ajustar la propiedad indefinida cuando se prueba. ¿Alguien puede ayudar a cómo lograr eso?

 const function2 = require(../function2) function setData(req) { if (!req) { return; } const data = function1(req); if (data) { const function2 = new function2(req); if (function2) { function2.setCode(data); ); } } }

mi borrador

 describe('test', ()=>{ context('setData', ()=>{ it('function2.setCode should be call', ()=>{ let mock = mock(setData); mock.expects("setCode").once(); setData(); mock.verify(); }) }) }
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!