Last active
August 2, 2019 09:06
-
-
Save Ufosek/4260c7f3c60f86625e759d452392bf0c to your computer and use it in GitHub Desktop.
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
// | |
// Our redux component to test | |
// | |
export default function ProfileComponent (props) { | |
const profile = useMySelector(state => state.profile, props) | |
// Invariant Violation: could not find react-redux context value; please ensure the component is wrapped in a <Provider> | |
// const profile = useSelector(state => state.profile) | |
return ( | |
<View> | |
{ profile.isLoaded && | |
<ProfileItem data={ profile.data } /> | |
} | |
... | |
</View> | |
) | |
} | |
// | |
// useMySelector wrapper | |
// | |
export function useMySelector(selector, props) { | |
if (props && props.mockedState) { | |
return props.mockedState | |
} | |
return useSelector(selector) | |
} | |
// | |
// Test | |
// | |
describe("ProfileComponent", () => { | |
describe("when is loaded", () => { | |
const state = { | |
isLoaded: true, | |
data: { ... } | |
} | |
const component = TestRenderer.create(<ProfileComponent mockedState={ state } />).root | |
it("should render ProfileItem", () => { | |
expect(component.findByType(ProfileItem)) | |
}) | |
it("should pass data to ProfileItem", () => { | |
expect(component.findByType(ProfileItem).props.data).toEqual(state.data) | |
}) | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment