Skip to content

Instantly share code, notes, and snippets.

@rickhanlonii
Last active February 20, 2019 11:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickhanlonii/bbdc87e4d8b26d0c13fb1715635ffb6f to your computer and use it in GitHub Desktop.
Save rickhanlonii/bbdc87e4d8b26d0c13fb1715635ffb6f to your computer and use it in GitHub Desktop.
Mock Test with jest.mock
import * as app from "./app";
import * as math from "./math";
// Set all module functions to jest.fn
jest.mock("./math.js");
test("calls math.add", () => {
app.doAdd(1, 2);
expect(math.add).toHaveBeenCalledWith(1, 2);
});
test("calls math.subtract", () => {
app.doSubtract(1, 2);
expect(math.subtract).toHaveBeenCalledWith(1, 2);
});
@chestozo
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment