Skip to content

Instantly share code, notes, and snippets.

@codegagan
Created August 30, 2020 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegagan/6344483f0bf4c365df36ef926cbe9b01 to your computer and use it in GitHub Desktop.
Save codegagan/6344483f0bf4c365df36ef926cbe9b01 to your computer and use it in GitHub Desktop.
Test the behavior defined in useEffect
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