Created
July 20, 2020 06:11
-
-
Save kylefritz/24ce374e019a0fa976ccbdb8668aa8b3 to your computer and use it in GitHub Desktop.
jest mocking
This file contains hidden or 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
require("../configure_enzyme"); | |
// | |
// setup a mock for a function that depends on the current system time | |
// | |
import { pastDeadline } from "menu/pastDeadline"; | |
jest.mock("menu/pastDeadline", () => { | |
let areWePastDeadline = true; | |
function __setPastDeadline(newValue) { | |
areWePastDeadline = newValue; | |
} | |
return { __setPastDeadline, pastDeadline: () => areWePastDeadline }; | |
}); | |
import { __setPastDeadline } from "menu/pastDeadline"; | |
test("__setPastDeadline back and forth in same test", () => { | |
__setPastDeadline(false); | |
expect(pastDeadline()).toBe(false); | |
__setPastDeadline(true); | |
expect(pastDeadline()).toBe(true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment