From 4af6d723f1006350ae6d64ea6bf46b6801c8ace1 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Thu, 19 May 2022 22:06:51 +0200 Subject: [PATCH 1/2] docs: add FAQ page and native features question --- website/docs/FAQ.md | 29 +++++++++++++++++++++++++++++ website/sidebars.js | 1 + 2 files changed, 30 insertions(+) create mode 100644 website/docs/FAQ.md diff --git a/website/docs/FAQ.md b/website/docs/FAQ.md new file mode 100644 index 000000000..a1327c411 --- /dev/null +++ b/website/docs/FAQ.md @@ -0,0 +1,29 @@ +--- +id: faq +title: FAQ +--- + +
+ Can I test native features of React Native apps? + +
+

Short answer: no.

+ +React Native Testing Library does not provide a full React Native runtime since that would require running on physical device +or iOS simulator/Android emulator to provide the underlying OS and platform APIs. + +Instead of using React Native renderer, we simulate only the JavaScript part of it runtime by using [React Test Renderer](https://reactjs.org/docs/test-renderer.html) and providing queries and `fireEvent` APIs that mimick certain behaviors from real runtime. + +This approach has certain benefits and shortfalse. On the plus side: + +- it allows testing most of the logic of regular React Native apps +- it allows running test on any OS supported by Jest or other test runner, e.g. on CI +- it uses much less resources than full runtime emulation +- you can use Jest fake timers + +The the negative side: + +- you cannot test native features +- certain JavaScript features might not be perfectly simulated by we are working on it + +
diff --git a/website/sidebars.js b/website/sidebars.js index 289508d94..cb675e03d 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -7,6 +7,7 @@ module.exports = { 'migration-v7', 'migration-v2', 'how-should-i-query', + 'faq', 'eslint-plugin-testing-library', ], Examples: ['react-navigation', 'redux-integration'], From 5c7e3c1a791d65a24dfd43631625be3cbfcf2c12 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Thu, 2 Jun 2022 11:31:14 +0200 Subject: [PATCH 2/2] docs: fixed grammar issues & added native examples --- website/docs/FAQ.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/website/docs/FAQ.md b/website/docs/FAQ.md index a1327c411..6e2f7e331 100644 --- a/website/docs/FAQ.md +++ b/website/docs/FAQ.md @@ -10,20 +10,24 @@ title: FAQ

Short answer: no.

React Native Testing Library does not provide a full React Native runtime since that would require running on physical device -or iOS simulator/Android emulator to provide the underlying OS and platform APIs. +or iOS simulator/Android emulator to provision the underlying OS and platform APIs. -Instead of using React Native renderer, we simulate only the JavaScript part of it runtime by using [React Test Renderer](https://reactjs.org/docs/test-renderer.html) and providing queries and `fireEvent` APIs that mimick certain behaviors from real runtime. +Instead of using React Native renderer, it simulates only the JavaScript part of its runtime by +using [React Test Renderer](https://reactjs.org/docs/test-renderer.html) while providing queries +and `fireEvent` APIs that mimick certain behaviors from the real runtime. -This approach has certain benefits and shortfalse. On the plus side: +This approach has certain benefits and shortfalls. On the positive side: - it allows testing most of the logic of regular React Native apps -- it allows running test on any OS supported by Jest or other test runner, e.g. on CI -- it uses much less resources than full runtime emulation +- it allows running test on any OS supported by Jest, or other test runner, e.g. on CI +- it uses much less resources than full runtime simulation - you can use Jest fake timers The the negative side: - you cannot test native features -- certain JavaScript features might not be perfectly simulated by we are working on it +- certain JavaScript features might not be perfectly simulated, but we are working on it + +For instance, [react-native's ScrollView](https://reactnative.dev/docs/scrollview) has several props that depend on native calls. While you can trigger `onScroll` call with `fireEvent.scroll`, `onMomentumScrollBegin` is called from the native side and will therefore not be called.