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

296
Views
¿Cómo simular una transacción de Sequelize con Sinon?

Estoy probando una función que crea un recurso usando Sequelize, estoy agregando transacciones porque quiero confirmar todo si no hay errores, tengo esto

 const createResource = async (resource) => { const t = await sequelize.transaction(); try { const createdResource = await Resource.create(resource, { transaction: t }); await t.commit(); return createdResource; } catch (err) { await t.rollback(); throw err; } };

La prueba unitaria para la función anterior, se ve así

 it('Should create a resource with no errors', function () { const dummy = aDummy(); const createFake = sinon.fake.resolves({ dataValues: dummy }); sinon.replace(Resource, 'create', createFake); return ResourceService.createResource(dummy) .then(res => { expect(res).to.not.be.undefined; expect(createFake.calledWith(dummy)); expect(createFake.calledOnce).to.be.true; }); });

Lo que quiero es no depender de ninguna infraestructura en absoluto, entonces mi problema es que no sé cómo simular una transacción de Sequelize con Sinon.

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!