I have successfully set up the Jest test environment in a React Native component that draws a Button
(basically a combination of Touchable
and Text
components).
I can run snapshot tests like the following:
test('Renders', () => {
const component = renderer.create(
<Button>
Button
</Button>
)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
However, I want to make a step further and start testing the props
of the component (i.e., checking that the Button text is passed as props.children
and I also want to test the onPress
functionality, simulating the user tap and checking that a passed function is called.
How can I do this with a Jest + React Native environment?
PS: I'm currently running this code with react-native ~> v0.34
, jest ~> v15.1.1
and jest-react-native ~> v15.0.0
.
Aucun commentaire:
Enregistrer un commentaire