Created
August 30, 2020 07:20
Test conditional rendering based on state
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 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