Created
August 30, 2020 08:14
-
-
Save codegagan/6344483f0bf4c365df36ef926cbe9b01 to your computer and use it in GitHub Desktop.
Test the behavior defined in useEffect
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
import * as reactModule from "react"; | |
import { shallow } from "enzyme"; | |
import EffectComponent from "./EffectComponent"; | |
describe("test App Component", () => { | |
it("should call the logic in useEffect", () => { | |
const setDataSize = jest.fn(size => {}); | |
reactModule.useState = jest.fn(initialDataSize => [ | |
initialDataSize, | |
setDataSize | |
]); | |
reactModule.useEffect = jest.fn((effectLogic, triggers) => effectLogic()); | |
wrapper = shallow(<EffectComponent />); | |
expect(setDataSize).toHaveBeenCalledWith(3); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment