numberkruncherN
Denoβ€’2y agoβ€’
8 replies
numberkruncher

How to mock modules like you can with jest?

With node/jest I was able to mock specific functions from modules using jest.mock at the start of the test file. How can I do this in Deno? I have a module which calls a function from another module:
import {foo} from "foo";

export function bar(a: number): number {
  return foo(a * 2);
}

How can I substitute foo with a mock/stub/fake for the scope of a test file?
jest.mock("foo", () => ({
  foo: jest.fn();
}));

import {foo} from "foo";

describe("example", () => {
  it("returns the expected number", () => {
    foo.mockImplementation((_) => 100);
    ...
Was this page helpful?