Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
How to mock esm modules functions with quibble

Is it feasible to mock and test an esm method something like this with quibble? If not do we have any other libraries for this?

Sinon was nice, but es modules cannot be stubbed with sinon. I found quibble from this SO answer.

My file to test:

module.mjs

export function getNumber() {
  return 10;
}

export function adder() {
  const a = getNumber();
  const b = getNumber();
  return a + b;
}

test for this file: module.test.mjs

import { expect } from "chai";
import quibble from "quibble";
import { adder } from "./module.js";

// passing
it("testing adder", () => {
  const result = adder();
  expect(result).to.equal(20);
});

// failing
it("mocked test", async () => {
  await quibble.esm("./module.js", {
    getNumber: () => 30,
  });
  const result = adder();
  expect(result).to.equal(60); // still returns 20
});
$ mocha --loader=quibble "**/*/module.test.js"
  ✔ testing adder
  1) mocked test

  1 passing (9ms)
  1 failing

  1) mocked test:

      AssertionError: expected 20 to equal 60
      + expected - actual

      -20
      +60
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda