Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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