Navigation Menu

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/6e6c634daaf30a32716a19edf71f8bee to your computer and use it in GitHub Desktop.
Save rickhanlonii/6e6c634daaf30a32716a19edf71f8bee to your computer and use it in GitHub Desktop.
Mock Test with jest.spyOn
import * as app from "./app";
import * as math from "./math";
test("calls math.add", () => {
const addMock = jest.spyOn(math, "add");
// calls the original implementation
expect(app.doAdd(1, 2)).toEqual(3);
// and the spy stores the calls to add
expect(addMock).toHaveBeenCalledWith(1, 2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment