jest-native
危險
此套件已過時,不再積極維護。
我們鼓勵您遷移至 React Native Testing Library v12.4 或更高版本,其中包含基於此儲存庫匹配器的現代內建 Jest 匹配器。遷移過程應該相對簡單,我們有可用的遷移指南。
Jest Native
是 React Native Testing Library
的配套函式庫,為 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()
注意:當使用這些匹配器時,您可能需要確保使用查詢函式(例如
queryByTestId
),而不是取得函式(例如getByTestId
)。否則,get*
函式可能會在您的斷言之前拋出錯誤。
請參閱 Jest Native 的文件,以取得可用匹配器的完整列表。