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

136
Views
Cómo desconectar el módulo IIFE

Estoy ejecutando Node v16.11.0. Intentando probar un módulo Worker que definí como tal:

 const Worker = (function(){ function start(){...} function stop(){...} function privateFunction1(){ ...some stuff ...calls privateFunction2(); } function privateFunction2(){...} return { start: start, stop: stop, /** for testing only:**/ _privateFunction1: privateFunction1, _privateFunction2: privateFunction2 } })(); module.exports = Worker;

Y en mi archivo de prueba tengo:

 const worker = require("../../worker"); const sinon = require("sinon"); const chai = require("chai"); var assert = chai.assert; var expect = chai.expect; describe("Worker", function () { const sandbox = sinon.createSandbox(); describe("#privateFunction1", function () { ..... beforeEach(function () { removeStub = sandbox.stub(worker, "_privateFunction2"); ....... }); afterEach(function () { sandbox.restore(); }); it("should test something", function () { let obj = {} //just for demo purposes assert.equal(worker._privateFunction1(obj), false); });

La expectativa aquí es que _privateFunction1() comenzará a ejecutarse, llamará a privateFunction2 y esa llamada será manejada por el stub.

Pero en su lugar se llama al método real. El stubbing no funciona.

¿Alguien tiene alguna idea de lo que falta aquí?

Gracias

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!