Testing

Testing React Native components using Enzyme is similar to testing React Components for the web. We can use the shallow rendering API to isolate a component for testing. Additionally, react-native-mock allows us to run these tests on a CI server.

Setup

To get started, we need to do a little bit of setup. Install the following dependencies.

  • babel-core

  • babel-eslint

  • babel-plugin-transform-object-rest-spread

  • babel-preset-es2015

  • babel-preset-react

  • chai

  • enzyme

  • mocha

  • react-addons-test-utils

  • react-dom

  • react-native-mock

  • sinon

Then, create a .babelrc file:

And finally add this task to package.json:

Example

Last updated

Was this helpful?