Working with component tests
When working with component tests in React Native, the recommended solution is to use react-native-testing-library
. This library is compatible with Jest, adds a rendering environment for your JavaScript application, and provides multiple useful selectors and other functions.
The easiest type of component test is to check for (unexpected) changes. This is called snapshot testing. The component will be rendered and transformed into an XML or JSON representation, called a snapshot. This snapshot is stored with the tests. The next time the test runs, it is used to check for changes.
The following code example shows a snapshot test for the HomeView
component of our example application:
import React from 'react'; import HomeView from '../src/views/home/Home.view'; import {render} from '@testing-library/react-native'; const genres = require('../assets/data/genres.json'); describe('testing HomeView', (...