id | title | sidebar_label |
---|---|---|
ecosystem-jest-native |
jest-native |
jest-native |
Jest Native
is a companion
library for React Native Testing Library
that provides custom element matchers
for Jest.
npm install --save-dev @testing-library/jest-native
;<View>
<View testID="not-empty">
<Text testID="empty" />
</View>
<Text testID="visible">Visible Example</Text>
</View>
expect(queryByTestId(baseElement, 'not-empty')).not.toBeEmpty()
expect(getByText(baseElement, 'Visible Example')).toBeVisible()
:::caution When using some of these matchers, you may need to make sure you use
a query function (like queryByTestId
) rather than a get function (like
getByTestId
). Otherwise the get*
function could throw an error before your
assertion. :::
Check out Jest Native's documentation for a full list of available matchers.