Last active
February 20, 2019 11:40
-
-
Save rickhanlonii/6e6c634daaf30a32716a19edf71f8bee to your computer and use it in GitHub Desktop.
Mock Test with jest.spyOn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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