jest-native
danger
This package is deprecated and is no longer actively maintained.
We encourage you to migrate to React Native Testing Library, v12.4 or later, which includes modern built-in Jest matchers based on the matchers for this repository. The migration process should be relatively straightforward, we have a migration guide available.
Jest Native
is a companion
library for React Native Testing Library
that provides custom element matchers
for Jest.
- npm
- Yarn
npm install --save-dev @testing-library/jest-native
yarn add --dev @testing-library/jest-native
const {queryByTestId} = render(
<View>
<View testID="not-empty">
<Text testID="empty" />
</View>
<Text testID="visible">Visible Example</Text>
</View>,
)
expect(queryByTestId('not-empty')).not.toBeEmpty()
Note: when using some of these matchers, you may need to make sure you use a query function (like
queryByTestId
) rather than a get function (likegetByTestId
). Otherwise theget*
function could throw an error before your assertion.
Check out Jest Native's documentation for a full list of available matchers.