Skip to content

Instantly share code, notes, and snippets.

@codegagan
Created August 30, 2020 07:20
Test conditional rendering based on state
import * as reactModule from "react";
import { shallow } from "enzyme";
import ConditionalComponent from "./ConditionalComponent";
describe("test Conditional component", () => {
it("should render while loading", () => {
const loadingValue = true;
reactModule.useState = jest.fn(initialLoadingValue => [
loadingValue,
() => {}
]);
wrapper = shallow(<ConditionalComponent />);
expect(wrapper).toMatchSnapshot();
});
it("should render after loading", () => {
const loadingValue = false;
reactModule.useState = jest.fn(initialLoadingValue => [
loadingValue,
() => {}
]);
wrapper = shallow(<ConditionalComponent />);
expect(wrapper).toMatchSnapshot();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment