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/ee1e73da7e1db0e3dbc1bbf812bb093f to your computer and use it in GitHub Desktop.
Save rickhanlonii/ee1e73da7e1db0e3dbc1bbf812bb093f to your computer and use it in GitHub Desktop.
Mock Test with jest.fn
import * as app from "./app";
import * as math from "./math";
math.add = jest.fn();
math.subtract = jest.fn();
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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment