lundi 29 juillet 2019

React Native Component Blackbox testing

Suppose I am developing a todo React app. I can select one or more to do items, and mark them done by clicking a "done" button.

Internally, this makes an API call to patch said items as done, then gets the items again and sets state to update the UI.

I want to test this using React test utils or something of the like by rendering the component and making assertions against the DOM. I don't want to test whether certain API function calls were called, state was changed etc.

Instead I want to test whether the user-facing UI changed after updating the items as done as a result of the internal state change. How do I do this without actually making API calls, or worse yet doing some kind of mocking madness, given that I'd have to stub the patch, and mock the API call to get all the items. This seems too implementation-focused and brittle.

Yes, child components accept just props and are easy to unit-test, but at some point you have a parent component that has to deal with state.

Aucun commentaire:

Enregistrer un commentaire