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

191
Views
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
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!