Created
August 30, 2020 07:20
-
-
Save codegagan/329b414ee72bf978b6db398d3a020fd0 to your computer and use it in GitHub Desktop.
Test conditional rendering based on state
This file contains 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