From 563d029ae6868c9a267c7875ec9a0ba58703e05c Mon Sep 17 00:00:00 2001 From: Youssouf EL Azizi Date: Mon, 6 Jan 2025 15:55:05 +0100 Subject: [PATCH] fea(docs): add docs for testing with react native testing library --- docs/pages/faq.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/pages/faq.md b/docs/pages/faq.md index 9c9bfd8e0..2b4e9bace 100644 --- a/docs/pages/faq.md +++ b/docs/pages/faq.md @@ -151,3 +151,39 @@ This is because the example app is configured as a Yarn workspace, and there is ```yml nodeLinker: node-modules ``` + + + +## Testing with React Native testing library + +To test with React Native testing library, you may need to use `@react-native/babel-preset` preset for test environment in `babel.config.js` file. + +```js +// babel.config.js +module.exports = { + presets: ['module:react-native-builder-bob/babel-preset'], + env: { + test: { + presets: ['module:@react-native/babel-preset'], + }, + }, +}; +``` +Then update the jest config in your `package.json` file. + +```json +// package.json +"jest": { + "preset": "react-native", + "modulePathIgnorePatterns": [ + "/example/node_modules", + "/lib/" + ], + "transformIgnorePatterns": [ + "node_modules/(?!(jest-)?react-native|@react-native|@react-native-community|react-native-reanimated)" + ], + "setupFilesAfterEnv": [ + "@testing-library/react-native/extend-expect" + ] + }, +```