This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the testing category.
Last Updated: 2024-11-23
I was writing my first test for cavy
an e2e testing tool for React Native.
Its API only had a handful of methods, and these seemed insufficient for my
testing purposes. E.g. they had pressOn()
but I wanted to use a Picker
component from React Native, and cavy
had no corresponding way to interact
with it.
What I should have done look up the Picker
object in the React Native docs
straight away and noticed that it has certain props, such as onValueChange
-
then putting 2 + 2 together and realizing that this was a public API I could
call. I could have pieced together the interaction in my test without any fancy
testing framework: I would just use cavy
to get a reference to the component.
const picker = await spec.findComponent('DriverLogin.UsernamePicker')
const username = "jack"
await picker.props.onValueChange(username) // pure React Native
The lesson here, ultimately, is to remember that tests are just regular code - not something special. This regular code should be my primary source for interacting with things in tests.