@testing-library/react-native 12.2.0 → 12.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (486) hide show
  1. package/build/fireEvent.js +1 -1
  2. package/build/fireEvent.js.map +1 -1
  3. package/build/helpers/component-tree.d.ts +11 -5
  4. package/build/helpers/component-tree.js +5 -1
  5. package/build/helpers/component-tree.js.map +1 -1
  6. package/build/helpers/findAll.d.ts +2 -1
  7. package/build/helpers/findAll.js +2 -1
  8. package/build/helpers/findAll.js.map +1 -1
  9. package/build/helpers/host-component-names.d.ts +11 -2
  10. package/build/helpers/host-component-names.js +10 -0
  11. package/build/helpers/host-component-names.js.map +1 -1
  12. package/build/helpers/matchers/matchLabelText.js +1 -1
  13. package/build/helpers/matchers/matchLabelText.js.map +1 -1
  14. package/build/queries/a11yState.js +1 -1
  15. package/build/queries/a11yState.js.map +1 -1
  16. package/build/queries/a11yValue.js +1 -1
  17. package/build/queries/a11yValue.js.map +1 -1
  18. package/build/queries/displayValue.js +5 -6
  19. package/build/queries/displayValue.js.map +1 -1
  20. package/build/queries/hintText.js +1 -1
  21. package/build/queries/hintText.js.map +1 -1
  22. package/build/queries/labelText.js +1 -1
  23. package/build/queries/labelText.js.map +1 -1
  24. package/build/queries/placeholderText.js +3 -4
  25. package/build/queries/placeholderText.js.map +1 -1
  26. package/build/queries/role.js +1 -1
  27. package/build/queries/role.js.map +1 -1
  28. package/build/queries/testId.js +3 -3
  29. package/build/queries/testId.js.map +1 -1
  30. package/build/queries/text.js +1 -2
  31. package/build/queries/text.js.map +1 -1
  32. package/build/render.js.map +1 -1
  33. package/build/user-event/clear.d.ts +3 -0
  34. package/build/user-event/clear.js +41 -0
  35. package/build/user-event/clear.js.map +1 -0
  36. package/build/user-event/index.d.ts +1 -0
  37. package/build/user-event/index.js +2 -1
  38. package/build/user-event/index.js.map +1 -1
  39. package/build/user-event/press/press.js +1 -4
  40. package/build/user-event/press/press.js.map +1 -1
  41. package/build/user-event/setup/setup.d.ts +14 -2
  42. package/build/user-event/setup/setup.js +3 -1
  43. package/build/user-event/setup/setup.js.map +1 -1
  44. package/build/user-event/type/type.d.ts +2 -1
  45. package/build/user-event/type/type.js +8 -4
  46. package/build/user-event/type/type.js.map +1 -1
  47. package/build/user-event/utils/host-components.d.ts +2 -0
  48. package/build/user-event/utils/host-components.js +11 -0
  49. package/build/user-event/utils/host-components.js.map +1 -0
  50. package/build/user-event/utils/index.d.ts +1 -0
  51. package/build/user-event/utils/index.js +11 -0
  52. package/build/user-event/utils/index.js.map +1 -1
  53. package/build/user-event/utils/text-range.d.ts +0 -1
  54. package/build/user-event/utils/text-range.js +0 -11
  55. package/build/user-event/utils/text-range.js.map +1 -1
  56. package/package.json +5 -4
  57. package/.DS_Store +0 -0
  58. package/.codecov.yml +0 -9
  59. package/.eslintcache +0 -1
  60. package/.eslintignore +0 -2
  61. package/.eslintrc +0 -19
  62. package/.flowconfig +0 -63
  63. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  64. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
  65. package/.github/ISSUE_TEMPLATE/question.md +0 -9
  66. package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
  67. package/.github/actions/setup-deps/action.yml +0 -22
  68. package/.github/actions/setup-website-deps/action.yml +0 -22
  69. package/.github/dependabot.yml +0 -10
  70. package/.github/workflows/deploy-website.yml +0 -36
  71. package/.github/workflows/example-apps.yml +0 -25
  72. package/.github/workflows/main.yml +0 -103
  73. package/.gitignore +0 -11
  74. package/.prettierrc.js +0 -5
  75. package/CODE_OF_CONDUCT.md +0 -73
  76. package/CONTRIBUTING.md +0 -64
  77. package/babel.config.js +0 -22
  78. package/build/helpers/filterNodeByType.d.ts +0 -3
  79. package/build/helpers/filterNodeByType.js +0 -9
  80. package/build/helpers/filterNodeByType.js.map +0 -1
  81. package/coverage/clover.xml +0 -1176
  82. package/coverage/coverage-final.json +0 -70
  83. package/coverage/lcov-report/base.css +0 -224
  84. package/coverage/lcov-report/block-navigation.js +0 -87
  85. package/coverage/lcov-report/favicon.png +0 -0
  86. package/coverage/lcov-report/index.html +0 -266
  87. package/coverage/lcov-report/prettify.css +0 -1
  88. package/coverage/lcov-report/prettify.js +0 -2
  89. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  90. package/coverage/lcov-report/sorter.js +0 -196
  91. package/coverage/lcov-report/src/act.ts.html +0 -343
  92. package/coverage/lcov-report/src/cleanup.ts.html +0 -130
  93. package/coverage/lcov-report/src/config.ts.html +0 -301
  94. package/coverage/lcov-report/src/fireEvent.ts.html +0 -559
  95. package/coverage/lcov-report/src/flushMicroTasks.ts.html +0 -124
  96. package/coverage/lcov-report/src/helpers/accessiblity.ts.html +0 -412
  97. package/coverage/lcov-report/src/helpers/component-tree.ts.html +0 -352
  98. package/coverage/lcov-report/src/helpers/debugDeep.ts.html +0 -166
  99. package/coverage/lcov-report/src/helpers/debugShallow.ts.html +0 -151
  100. package/coverage/lcov-report/src/helpers/deprecation.ts.html +0 -244
  101. package/coverage/lcov-report/src/helpers/errors.ts.html +0 -283
  102. package/coverage/lcov-report/src/helpers/filterNodeByType.ts.html +0 -106
  103. package/coverage/lcov-report/src/helpers/findAll.ts.html +0 -289
  104. package/coverage/lcov-report/src/helpers/format-default.ts.html +0 -301
  105. package/coverage/lcov-report/src/helpers/format.ts.html +0 -226
  106. package/coverage/lcov-report/src/helpers/getTextContent.ts.html +0 -145
  107. package/coverage/lcov-report/src/helpers/host-component-names.tsx.html +0 -286
  108. package/coverage/lcov-report/src/helpers/index.html +0 -326
  109. package/coverage/lcov-report/src/helpers/matchers/accessibilityState.ts.html +0 -229
  110. package/coverage/lcov-report/src/helpers/matchers/accessibilityValue.ts.html +0 -157
  111. package/coverage/lcov-report/src/helpers/matchers/index.html +0 -206
  112. package/coverage/lcov-report/src/helpers/matchers/matchArrayProp.ts.html +0 -148
  113. package/coverage/lcov-report/src/helpers/matchers/matchLabelText.ts.html +0 -238
  114. package/coverage/lcov-report/src/helpers/matchers/matchObjectProp.ts.html +0 -160
  115. package/coverage/lcov-report/src/helpers/matchers/matchStringProp.ts.html +0 -154
  116. package/coverage/lcov-report/src/helpers/matchers/matchTextContent.ts.html +0 -145
  117. package/coverage/lcov-report/src/helpers/query-name.ts.html +0 -97
  118. package/coverage/lcov-report/src/helpers/stringValidation.ts.html +0 -193
  119. package/coverage/lcov-report/src/helpers/timers.ts.html +0 -382
  120. package/coverage/lcov-report/src/index.html +0 -356
  121. package/coverage/lcov-report/src/index.ts.html +0 -184
  122. package/coverage/lcov-report/src/matches.ts.html +0 -232
  123. package/coverage/lcov-report/src/pure.ts.html +0 -157
  124. package/coverage/lcov-report/src/queries/a11yState.ts.html +0 -478
  125. package/coverage/lcov-report/src/queries/a11yValue.ts.html +0 -478
  126. package/coverage/lcov-report/src/queries/displayValue.ts.html +0 -319
  127. package/coverage/lcov-report/src/queries/hintText.ts.html +0 -421
  128. package/coverage/lcov-report/src/queries/index.html +0 -281
  129. package/coverage/lcov-report/src/queries/labelText.ts.html +0 -262
  130. package/coverage/lcov-report/src/queries/makeQueries.ts.html +0 -850
  131. package/coverage/lcov-report/src/queries/placeholderText.ts.html +0 -322
  132. package/coverage/lcov-report/src/queries/role.ts.html +0 -481
  133. package/coverage/lcov-report/src/queries/testId.ts.html +0 -298
  134. package/coverage/lcov-report/src/queries/text.ts.html +0 -283
  135. package/coverage/lcov-report/src/queries/unsafeProps.ts.html +0 -313
  136. package/coverage/lcov-report/src/queries/unsafeType.ts.html +0 -304
  137. package/coverage/lcov-report/src/react-versions.ts.html +0 -118
  138. package/coverage/lcov-report/src/render-act.ts.html +0 -142
  139. package/coverage/lcov-report/src/render.tsx.html +0 -592
  140. package/coverage/lcov-report/src/renderHook.tsx.html +0 -262
  141. package/coverage/lcov-report/src/screen.ts.html +0 -454
  142. package/coverage/lcov-report/src/shallow.ts.html +0 -139
  143. package/coverage/lcov-report/src/test-utils/events.ts.html +0 -145
  144. package/coverage/lcov-report/src/test-utils/index.html +0 -131
  145. package/coverage/lcov-report/src/test-utils/index.ts.html +0 -88
  146. package/coverage/lcov-report/src/user-event/event-builder/common.ts.html +0 -229
  147. package/coverage/lcov-report/src/user-event/event-builder/index.html +0 -146
  148. package/coverage/lcov-report/src/user-event/event-builder/index.ts.html +0 -106
  149. package/coverage/lcov-report/src/user-event/event-builder/test-input.ts.html +0 -343
  150. package/coverage/lcov-report/src/user-event/event-builder/text-input.ts.html +0 -343
  151. package/coverage/lcov-report/src/user-event/index.html +0 -116
  152. package/coverage/lcov-report/src/user-event/index.ts.html +0 -121
  153. package/coverage/lcov-report/src/user-event/press/index.html +0 -131
  154. package/coverage/lcov-report/src/user-event/press/index.ts.html +0 -88
  155. package/coverage/lcov-report/src/user-event/press/press.ts.html +0 -133
  156. package/coverage/lcov-report/src/user-event/setup/index.html +0 -131
  157. package/coverage/lcov-report/src/user-event/setup/index.ts.html +0 -91
  158. package/coverage/lcov-report/src/user-event/setup/setup.ts.html +0 -358
  159. package/coverage/lcov-report/src/user-event/type/index.html +0 -146
  160. package/coverage/lcov-report/src/user-event/type/index.ts.html +0 -88
  161. package/coverage/lcov-report/src/user-event/type/parseKeys.ts.html +0 -208
  162. package/coverage/lcov-report/src/user-event/type/type.ts.html +0 -484
  163. package/coverage/lcov-report/src/user-event/utils/content-size.ts.html +0 -160
  164. package/coverage/lcov-report/src/user-event/utils/dispatch-event.ts.html +0 -367
  165. package/coverage/lcov-report/src/user-event/utils/events.ts.html +0 -247
  166. package/coverage/lcov-report/src/user-event/utils/index.html +0 -176
  167. package/coverage/lcov-report/src/user-event/utils/index.ts.html +0 -97
  168. package/coverage/lcov-report/src/user-event/utils/text-range.ts.html +0 -118
  169. package/coverage/lcov-report/src/user-event/utils/wait.ts.html +0 -130
  170. package/coverage/lcov-report/src/waitFor.ts.html +0 -772
  171. package/coverage/lcov-report/src/waitForElementToBeRemoved.ts.html +0 -211
  172. package/coverage/lcov-report/src/within.ts.html +0 -175
  173. package/coverage/lcov.info +0 -2614
  174. package/examples/.DS_Store +0 -0
  175. package/examples/basic/.expo/README.md +0 -17
  176. package/examples/basic/.expo/devices.json +0 -3
  177. package/examples/basic/.expo/packager-info.json +0 -4
  178. package/examples/basic/.expo/settings.json +0 -8
  179. package/examples/basic/.expo-shared/assets.json +0 -4
  180. package/examples/basic/.gitignore +0 -14
  181. package/examples/basic/App.tsx +0 -20
  182. package/examples/basic/README.md +0 -11
  183. package/examples/basic/__tests__/App.test.tsx +0 -119
  184. package/examples/basic/app.json +0 -31
  185. package/examples/basic/assets/adaptive-icon.png +0 -0
  186. package/examples/basic/assets/favicon.png +0 -0
  187. package/examples/basic/assets/icon.png +0 -0
  188. package/examples/basic/assets/splash.png +0 -0
  189. package/examples/basic/babel.config.js +0 -6
  190. package/examples/basic/components/Home.tsx +0 -28
  191. package/examples/basic/components/LoginForm.tsx +0 -138
  192. package/examples/basic/jest-setup.ts +0 -7
  193. package/examples/basic/jest.config.js +0 -5
  194. package/examples/basic/package.json +0 -30
  195. package/examples/basic/tsconfig.json +0 -7
  196. package/examples/basic/yarn-error.log +0 -8083
  197. package/examples/basic/yarn.lock +0 -8878
  198. package/examples/react-navigation/README.md +0 -16
  199. package/examples/react-navigation/babel.config.js +0 -4
  200. package/examples/react-navigation/jest-setup.js +0 -11
  201. package/examples/react-navigation/jest.config.js +0 -10
  202. package/examples/react-navigation/package.json +0 -31
  203. package/examples/react-navigation/src/App.js +0 -21
  204. package/examples/react-navigation/src/DrawerNavigator.js +0 -15
  205. package/examples/react-navigation/src/DrawerNavigator.test.js +0 -42
  206. package/examples/react-navigation/src/NativeStackNavigator.js +0 -15
  207. package/examples/react-navigation/src/NativeStackNavigator.test.js +0 -34
  208. package/examples/react-navigation/src/StackNavigator.js +0 -15
  209. package/examples/react-navigation/src/StackNavigator.test.js +0 -34
  210. package/examples/react-navigation/src/TabNavigator.js +0 -15
  211. package/examples/react-navigation/src/TabNavigator.test.js +0 -21
  212. package/examples/react-navigation/src/screens/DetailsScreen.js +0 -43
  213. package/examples/react-navigation/src/screens/DetailsScreen.test.js +0 -27
  214. package/examples/react-navigation/src/screens/DrawerHomeScreen.js +0 -26
  215. package/examples/react-navigation/src/screens/HomeScreen.js +0 -48
  216. package/examples/react-navigation/src/screens/SettingsScreen.js +0 -20
  217. package/examples/react-navigation/src/test-utils.js +0 -12
  218. package/examples/react-navigation/yarn.lock +0 -5610
  219. package/examples/redux/App.js +0 -27
  220. package/examples/redux/README.md +0 -5
  221. package/examples/redux/actions/todoActions.js +0 -25
  222. package/examples/redux/babel.config.js +0 -6
  223. package/examples/redux/components/AddTodo.js +0 -73
  224. package/examples/redux/components/AddTodo.test.js +0 -27
  225. package/examples/redux/components/TodoElem.js +0 -25
  226. package/examples/redux/components/TodoList.js +0 -29
  227. package/examples/redux/components/TodoList.test.js +0 -34
  228. package/examples/redux/index.js +0 -8
  229. package/examples/redux/jest-setup.js +0 -2
  230. package/examples/redux/jest.config.js +0 -4
  231. package/examples/redux/package.json +0 -23
  232. package/examples/redux/reducers/index.js +0 -6
  233. package/examples/redux/reducers/todoReducer.js +0 -27
  234. package/examples/redux/store.js +0 -10
  235. package/examples/redux/test-utils.js +0 -11
  236. package/examples/redux/yarn-error.log +0 -8083
  237. package/examples/redux/yarn.lock +0 -8423
  238. package/experiments-app/.expo/README.md +0 -15
  239. package/experiments-app/.expo/devices.json +0 -3
  240. package/experiments-app/.expo/settings.json +0 -10
  241. package/experiments-app/.gitignore +0 -17
  242. package/experiments-app/.prettierrc.js +0 -5
  243. package/experiments-app/app.json +0 -30
  244. package/experiments-app/assets/adaptive-icon.png +0 -0
  245. package/experiments-app/assets/favicon.png +0 -0
  246. package/experiments-app/assets/icon.png +0 -0
  247. package/experiments-app/assets/splash.png +0 -0
  248. package/experiments-app/babel.config.js +0 -6
  249. package/experiments-app/index.js +0 -4
  250. package/experiments-app/package.json +0 -31
  251. package/experiments-app/src/App.tsx +0 -31
  252. package/experiments-app/src/MainScreen.tsx +0 -51
  253. package/experiments-app/src/experiments.ts +0 -17
  254. package/experiments-app/src/screens/TextInputEventPropagation.tsx +0 -54
  255. package/experiments-app/src/screens/TextInputEvents.tsx +0 -60
  256. package/experiments-app/src/utils/helpers.ts +0 -8
  257. package/experiments-app/tsconfig.json +0 -6
  258. package/experiments-app/yarn.lock +0 -6913
  259. package/flow-typed/npm/jest_v26.x.x.js +0 -1218
  260. package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -81
  261. package/jest-setup.ts +0 -10
  262. package/renovate.json +0 -19
  263. package/scripts/test_react_17 +0 -12
  264. package/src/.DS_Store +0 -0
  265. package/src/__tests__/.DS_Store +0 -0
  266. package/src/__tests__/__snapshots__/render-debug.test.tsx.snap +0 -548
  267. package/src/__tests__/__snapshots__/render.test.tsx.snap +0 -39
  268. package/src/__tests__/act.test.tsx +0 -56
  269. package/src/__tests__/auto-cleanup-skip.test.tsx +0 -39
  270. package/src/__tests__/auto-cleanup.test.tsx +0 -50
  271. package/src/__tests__/cleanup.test.tsx +0 -26
  272. package/src/__tests__/config.test.ts +0 -55
  273. package/src/__tests__/fireEvent-textInput.test.tsx +0 -154
  274. package/src/__tests__/fireEvent.test.tsx +0 -485
  275. package/src/__tests__/host-component-names.test.tsx +0 -109
  276. package/src/__tests__/host-text-nesting.test.tsx +0 -90
  277. package/src/__tests__/jest-native.test.tsx +0 -84
  278. package/src/__tests__/questionsBoard.test.tsx +0 -62
  279. package/src/__tests__/react-native-api.test.tsx +0 -126
  280. package/src/__tests__/render-debug.test.tsx +0 -207
  281. package/src/__tests__/render-stringValidation.test.tsx +0 -157
  282. package/src/__tests__/render.test.tsx +0 -256
  283. package/src/__tests__/renderHook.test.tsx +0 -114
  284. package/src/__tests__/screen.test.tsx +0 -66
  285. package/src/__tests__/timerUtils.ts +0 -7
  286. package/src/__tests__/timers.test.ts +0 -27
  287. package/src/__tests__/waitFor.test.tsx +0 -327
  288. package/src/__tests__/waitForElementToBeRemoved.test.tsx +0 -151
  289. package/src/__tests__/within.test.tsx +0 -96
  290. package/src/act.ts +0 -86
  291. package/src/cleanup.ts +0 -15
  292. package/src/config.ts +0 -72
  293. package/src/fireEvent.ts +0 -159
  294. package/src/flush-micro-tasks.ts +0 -30
  295. package/src/helpers/__tests__/accessiblity.test.tsx +0 -373
  296. package/src/helpers/__tests__/component-tree.test.tsx +0 -226
  297. package/src/helpers/__tests__/format-default.tsx +0 -114
  298. package/src/helpers/__tests__/getTextContent.test.tsx +0 -49
  299. package/src/helpers/__tests__/includeHiddenElements.test.tsx +0 -39
  300. package/src/helpers/__tests__/query-name.test.ts +0 -10
  301. package/src/helpers/__tests__/timers.test.ts +0 -8
  302. package/src/helpers/accessiblity.ts +0 -108
  303. package/src/helpers/component-tree.ts +0 -89
  304. package/src/helpers/debugDeep.ts +0 -27
  305. package/src/helpers/debugShallow.ts +0 -22
  306. package/src/helpers/deprecation.ts +0 -53
  307. package/src/helpers/errors.ts +0 -66
  308. package/src/helpers/filterNodeByType.ts +0 -7
  309. package/src/helpers/findAll.ts +0 -68
  310. package/src/helpers/format-default.ts +0 -72
  311. package/src/helpers/format.ts +0 -47
  312. package/src/helpers/getTextContent.ts +0 -20
  313. package/src/helpers/host-component-names.tsx +0 -75
  314. package/src/helpers/matchers/__tests__/matchArrayValue.test.ts +0 -34
  315. package/src/helpers/matchers/__tests__/matchObject.test.ts +0 -37
  316. package/src/helpers/matchers/__tests__/matchStringValue.test.ts +0 -15
  317. package/src/helpers/matchers/accessibilityState.ts +0 -48
  318. package/src/helpers/matchers/accessibilityValue.ts +0 -24
  319. package/src/helpers/matchers/matchArrayProp.ts +0 -21
  320. package/src/helpers/matchers/matchLabelText.ts +0 -51
  321. package/src/helpers/matchers/matchObjectProp.ts +0 -25
  322. package/src/helpers/matchers/matchStringProp.ts +0 -23
  323. package/src/helpers/matchers/matchTextContent.ts +0 -20
  324. package/src/helpers/pointer-events.ts +0 -27
  325. package/src/helpers/query-name.ts +0 -4
  326. package/src/helpers/stringValidation.ts +0 -36
  327. package/src/helpers/timers.ts +0 -98
  328. package/src/index.ts +0 -33
  329. package/src/matches.ts +0 -49
  330. package/src/pure.ts +0 -27
  331. package/src/queries/__tests__/a11yState.test.tsx +0 -439
  332. package/src/queries/__tests__/a11yValue.test.tsx +0 -309
  333. package/src/queries/__tests__/displayValue.test.tsx +0 -221
  334. package/src/queries/__tests__/hintText.test.tsx +0 -177
  335. package/src/queries/__tests__/labelText.test.tsx +0 -242
  336. package/src/queries/__tests__/makeQueries.test.tsx +0 -235
  337. package/src/queries/__tests__/placeholderText.test.tsx +0 -136
  338. package/src/queries/__tests__/role-value.test.tsx +0 -176
  339. package/src/queries/__tests__/role.test.tsx +0 -824
  340. package/src/queries/__tests__/testId.test.tsx +0 -200
  341. package/src/queries/__tests__/text.test.tsx +0 -556
  342. package/src/queries/a11yState.ts +0 -131
  343. package/src/queries/a11yValue.ts +0 -131
  344. package/src/queries/displayValue.ts +0 -78
  345. package/src/queries/hintText.ts +0 -112
  346. package/src/queries/labelText.ts +0 -59
  347. package/src/queries/makeQueries.ts +0 -255
  348. package/src/queries/options.ts +0 -14
  349. package/src/queries/placeholderText.ts +0 -79
  350. package/src/queries/role.ts +0 -132
  351. package/src/queries/testId.ts +0 -71
  352. package/src/queries/text.ts +0 -66
  353. package/src/queries/unsafeProps.ts +0 -76
  354. package/src/queries/unsafeType.ts +0 -73
  355. package/src/react-versions.ts +0 -11
  356. package/src/render-act.ts +0 -19
  357. package/src/render.tsx +0 -183
  358. package/src/renderHook.tsx +0 -56
  359. package/src/screen.ts +0 -123
  360. package/src/shallow.ts +0 -18
  361. package/src/test-utils/events.ts +0 -24
  362. package/src/test-utils/index.ts +0 -1
  363. package/src/user-event/event-builder/common.ts +0 -66
  364. package/src/user-event/event-builder/index.ts +0 -7
  365. package/src/user-event/event-builder/text-input.ts +0 -86
  366. package/src/user-event/index.ts +0 -17
  367. package/src/user-event/press/__tests__/longPress.real-timers.test.tsx +0 -117
  368. package/src/user-event/press/__tests__/longPress.test.tsx +0 -157
  369. package/src/user-event/press/__tests__/press.real-timers.test.tsx +0 -320
  370. package/src/user-event/press/__tests__/press.test.tsx +0 -457
  371. package/src/user-event/press/constants.ts +0 -7
  372. package/src/user-event/press/index.ts +0 -1
  373. package/src/user-event/press/press.ts +0 -169
  374. package/src/user-event/setup/index.ts +0 -2
  375. package/src/user-event/setup/setup.ts +0 -127
  376. package/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap +0 -339
  377. package/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap +0 -668
  378. package/src/user-event/type/__tests__/parseKeys.test.ts +0 -23
  379. package/src/user-event/type/__tests__/type-managed.test.tsx +0 -121
  380. package/src/user-event/type/__tests__/type.test.tsx +0 -336
  381. package/src/user-event/type/index.ts +0 -1
  382. package/src/user-event/type/parseKeys.ts +0 -41
  383. package/src/user-event/type/type.ts +0 -135
  384. package/src/user-event/utils/__tests__/dispatch-event.test.tsx +0 -41
  385. package/src/user-event/utils/__tests__/wait.test.ts +0 -63
  386. package/src/user-event/utils/content-size.ts +0 -25
  387. package/src/user-event/utils/dispatch-event.ts +0 -38
  388. package/src/user-event/utils/index.ts +0 -5
  389. package/src/user-event/utils/text-range.ts +0 -11
  390. package/src/user-event/utils/wait.ts +0 -15
  391. package/src/user-event/utils/warn-about-real-timers.ts +0 -13
  392. package/src/waitFor.ts +0 -228
  393. package/src/waitForElementToBeRemoved.ts +0 -42
  394. package/src/within.ts +0 -30
  395. package/tsconfig.json +0 -17
  396. package/tsconfig.release.json +0 -8
  397. package/website/.DS_Store +0 -0
  398. package/website/.docusaurus/DONT-EDIT-THIS-FOLDER +0 -5
  399. package/website/.docusaurus/client-modules.js +0 -6
  400. package/website/.docusaurus/codeTranslations.json +0 -1
  401. package/website/.docusaurus/docusaurus-plugin-content-blog/default/blog-post-list-prop-default.json +0 -4
  402. package/website/.docusaurus/docusaurus-plugin-content-blog/default/plugin-route-context-module-100.json +0 -4
  403. package/website/.docusaurus/docusaurus-plugin-content-docs/default/plugin-route-context-module-100.json +0 -4
  404. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-api-md-c82.json +0 -27
  405. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-eslint-p-llugin-testing-library-md-d24.json +0 -27
  406. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-faq-md-ad8.json +0 -27
  407. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-getting-started-md-8a6.json +0 -23
  408. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-how-should-i-query-md-f2d.json +0 -27
  409. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-migration-v-11-md-add.json +0 -27
  410. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-migration-v-12-md-14f.json +0 -27
  411. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-migration-v-2-md-698.json +0 -27
  412. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-migration-v-7-md-6bb.json +0 -27
  413. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-migration-v-9-md-f69.json +0 -27
  414. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-queries-md-7ad.json +0 -27
  415. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-react-navigation-md-1bd.json +0 -27
  416. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-redux-integration-md-77b.json +0 -23
  417. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-testing-environment-md-1c6.json +0 -27
  418. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-troubleshooting-md-01d.json +0 -27
  419. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-understanding-act-md-aa9.json +0 -27
  420. package/website/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-user-event-md-501.json +0 -27
  421. package/website/.docusaurus/docusaurus-plugin-content-docs/default/version-current-metadata-prop-751.json +0 -268
  422. package/website/.docusaurus/docusaurus-plugin-content-docs/react-native-testing-library-docs-route-96e.json +0 -115
  423. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-api-md-c82.json +0 -19
  424. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-eslint-p-llugin-testing-library-md-d24.json +0 -19
  425. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-faq-md-ad8.json +0 -19
  426. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-getting-started-md-8a6.json +0 -15
  427. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-how-should-i-query-md-f2d.json +0 -19
  428. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-migration-v-11-md-add.json +0 -19
  429. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-migration-v-2-md-698.json +0 -19
  430. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-migration-v-7-md-6bb.json +0 -19
  431. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-migration-v-9-md-f69.json +0 -19
  432. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-queries-md-7ad.json +0 -19
  433. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-react-navigation-md-1bd.json +0 -19
  434. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-redux-integration-md-77b.json +0 -15
  435. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-troubleshooting-md-01d.json +0 -19
  436. package/website/.docusaurus/docusaurus-plugin-content-docs/site-docs-understanding-act-md-aa9.json +0 -19
  437. package/website/.docusaurus/docusaurus-plugin-content-pages/default/plugin-route-context-module-100.json +0 -4
  438. package/website/.docusaurus/docusaurus-plugin-debug/default/docusaurus-debug-all-content-673.json +0 -623
  439. package/website/.docusaurus/docusaurus-plugin-debug/default/plugin-route-context-module-100.json +0 -4
  440. package/website/.docusaurus/docusaurus-theme-search-algolia/default/plugin-route-context-module-100.json +0 -4
  441. package/website/.docusaurus/docusaurus.config.js +0 -267
  442. package/website/.docusaurus/docusaurus.config.mjs +0 -365
  443. package/website/.docusaurus/globalData.json +0 -113
  444. package/website/.docusaurus/i18n.json +0 -17
  445. package/website/.docusaurus/registry.js +0 -35
  446. package/website/.docusaurus/routes.js +0 -162
  447. package/website/.docusaurus/routesChunkNames.json +0 -133
  448. package/website/.docusaurus/site-metadata.json +0 -36
  449. package/website/.gitignore +0 -20
  450. package/website/README.md +0 -33
  451. package/website/docker/.dockerignore +0 -3
  452. package/website/docker/Dockerfile +0 -9
  453. package/website/docker/docker-compose.yml +0 -11
  454. package/website/docs/API.md +0 -940
  455. package/website/docs/EslintPLluginTestingLibrary.md +0 -28
  456. package/website/docs/FAQ.md +0 -44
  457. package/website/docs/GettingStarted.md +0 -100
  458. package/website/docs/HowShouldIQuery.md +0 -21
  459. package/website/docs/MigrationV11.md +0 -64
  460. package/website/docs/MigrationV12.md +0 -67
  461. package/website/docs/MigrationV2.md +0 -126
  462. package/website/docs/MigrationV7.md +0 -119
  463. package/website/docs/MigrationV9.md +0 -67
  464. package/website/docs/Queries.md +0 -567
  465. package/website/docs/ReactNavigation.md +0 -371
  466. package/website/docs/ReduxIntegration.md +0 -137
  467. package/website/docs/TestingEnvironment.md +0 -154
  468. package/website/docs/Troubleshooting.md +0 -44
  469. package/website/docs/UnderstandingAct.md +0 -227
  470. package/website/docs/UserEvent.md +0 -143
  471. package/website/docusaurus.config.js +0 -114
  472. package/website/package.json +0 -31
  473. package/website/sidebars.js +0 -20
  474. package/website/src/components/Feature.js +0 -31
  475. package/website/src/css/custom.css +0 -13
  476. package/website/src/css/index.module.css +0 -77
  477. package/website/src/pages/index.js +0 -82
  478. package/website/static/.nojekyll +0 -0
  479. package/website/static/css/custom.css +0 -28
  480. package/website/static/img/hit.png +0 -0
  481. package/website/static/img/locomotive.png +0 -0
  482. package/website/static/img/owl.png +0 -0
  483. package/website/static/img/tools.png +0 -0
  484. package/website/yarn.lock +0 -7669
  485. package/yarn-error.log +0 -10613
  486. package/yarn.lock +0 -7765
@@ -1,940 +0,0 @@
1
- ---
2
- id: api
3
- title: API
4
- ---
5
-
6
- ### Table of contents:
7
-
8
- - [`render`](#render)
9
- - [`render` options](#render-options)
10
- - [`...queries`](#queries)
11
- - [`update`](#update)
12
- - [`unmount`](#unmount)
13
- - [`debug`](#debug)
14
- - [`toJSON`](#tojson)
15
- - [`root`](#root)
16
- - [`UNSAFE_root`](#unsaferoot)
17
- - [`screen`](#screen)
18
- - [`cleanup`](#cleanup)
19
- - [`fireEvent`](#fireevent)
20
- - [`fireEvent[eventName]`](#fireeventeventname)
21
- - [`fireEvent.press`](#fireeventpress)
22
- - [`fireEvent.changeText`](#fireeventchangetext)
23
- - [`fireEvent.scroll`](#fireeventscroll)
24
- - [`waitFor`](#waitfor)
25
- - [Using a React Native version \< 0.71 with Jest fake timers](#using-a-react-native-version--071-with-jest-fake-timers)
26
- - [`waitForElementToBeRemoved`](#waitforelementtoberemoved)
27
- - [`within`, `getQueriesForElement`](#within-getqueriesforelement)
28
- - [`queryBy*` APIs](#queryby-apis)
29
- - [`queryAll*` APIs](#queryall-apis)
30
- - [`act`](#act)
31
- - [`renderHook`](#renderhook)
32
- - [`callback`](#callback)
33
- - [`options` (Optional)](#options-optional)
34
- - [`RenderHookResult` object](#renderhookresult-object)
35
- - [Examples](#examples)
36
- - [Configuration](#configuration)
37
- - [`configure`](#configure)
38
- - [`resetToDefaults()`](#resettodefaults)
39
- - [Environment variables](#environment-variables)
40
- - [Accessibility](#accessibility)
41
- - [`isHiddenFromAccessibility`](#ishiddenfromaccessibility)
42
-
43
- This page gathers public API of React Native Testing Library along with usage examples.
44
-
45
- ## `render`
46
-
47
- - [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/render.test.tsx)
48
-
49
- Defined as:
50
-
51
- ```jsx
52
- function render(
53
- component: React.Element<any>,
54
- options?: RenderOptions
55
- ): RenderResult {}
56
- ```
57
-
58
- Deeply renders given React element and returns helpers to query the output components structure.
59
-
60
- ```jsx
61
- import { render } from '@testing-library/react-native';
62
- import { QuestionsBoard } from '../QuestionsBoard';
63
-
64
- test('should verify two questions', () => {
65
- render(<QuestionsBoard {...props} />);
66
- const allQuestions = screen.queryAllByRole('header');
67
-
68
- expect(allQuestions).toHaveLength(2);
69
- });
70
- ```
71
-
72
- > When using React context providers, like Redux Provider, you'll likely want to wrap rendered component with them. In such cases it's convenient to create your custom `render` method. [Follow this great guide on how to set this up](https://testing-library.com/docs/react-testing-library/setup#custom-render).
73
-
74
- The `render` method returns a `RenderResult` object having properties described below.
75
-
76
- :::info
77
- Latest `render` result is kept in [`screen`](#screen) variable that can be imported from `@testing-library/react-native` package.
78
-
79
- Using `screen` instead of destructuring `render` result is recommended approach. See [this article](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen) from Kent C. Dodds for more details.
80
- :::
81
-
82
- ### `render` options
83
-
84
- The behavior of `render` method can be customized by passing various options as a second argument of `RenderOptions` type:
85
-
86
- #### `wrapper` option
87
-
88
- ```ts
89
- wrapper?: React.ComponentType<any>,
90
- ```
91
-
92
- This options allows you to wrap tested component, passed as the first option to the `render()` function, in additional wrapper component. This is most useful for creating reusable custom render functions for common React Context providers.
93
-
94
- #### `createNodeMock` option
95
-
96
- ```ts
97
- createNodeMock?: (element: React.Element<any>) => any,
98
- ```
99
-
100
- This options allows you to pass `createNodeMock` option to `ReactTestRenderer.create()` method in order to allow for custom mock refs. You can learn more about this options from [React Test Renderer documentation](https://reactjs.org/docs/test-renderer.html#ideas).
101
-
102
- #### `unstable_validateStringsRenderedWithinText` option
103
-
104
- ```ts
105
- unstable_validateStringsRenderedWithinText?: boolean;
106
- ```
107
-
108
- :::note
109
- This options is experimental, in some cases it might not work as intended, and its behavior might change without observing [SemVer](https://semver.org/) requirements for breaking changes.
110
- :::
111
-
112
- This **experimental** option allows you to replicate React Native behavior of throwing `Invariant Violation: Text strings must be rendered within a <Text> component` error when you try to render `string` value under components different than `<Text>`, e.g. under `<View>`.
113
-
114
- This check is not enforced by React Test Renderer and hence by default React Native Testing Library also does not check this. That might result in runtime errors when running your code on a device, while the code works without errors in tests.
115
-
116
- ### `...queries`
117
-
118
- The most important feature of `render` is providing a set of helpful queries that allow you to find certain elements in the view hierarchy.
119
-
120
- See [Queries](./Queries.md) for a complete list.
121
-
122
- #### Example
123
-
124
- ```jsx
125
- import { render } from '@testing-library/react-native';
126
-
127
- const { getByText, queryByA11yState } = render(<Component />);
128
- ```
129
-
130
- ### `update`
131
-
132
- _Also available under `rerender` alias_
133
-
134
- ```ts
135
- update(element: React.Element<any>): void
136
- rerender(element: React.Element<any>): void
137
- ```
138
-
139
- Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree. This is useful when testing for `componentDidUpdate` behavior, by passing updated props to the component.
140
-
141
- [Example code](https://github.com/callstack/react-native-testing-library/blob/f96d782d26dd4815dbfd01de6ef7a647efd1f693/src/__tests__/act.test.js#L31-L37)
142
-
143
- ### `unmount`
144
-
145
- ```ts
146
- unmount(): void
147
- ```
148
-
149
- Unmount the in-memory tree, triggering the appropriate lifecycle events.
150
-
151
- :::note
152
- Usually you should not need to call `unmount` as it is done automatically if your test runner supports `afterEach` hook (like Jest, mocha, Jasmine).
153
- :::
154
-
155
- ### `debug`
156
-
157
- ```ts
158
- interface DebugOptions {
159
- message?: string;
160
- mapProps?: MapPropsFunction;
161
- }
162
-
163
- debug(options?: DebugOptions | string): void
164
- ```
165
-
166
- Pretty prints deeply rendered component passed to `render`.
167
-
168
- #### `message` option
169
-
170
- You can provide a message that will be printed on top.
171
-
172
- ```jsx
173
- render(<Component />);
174
- screen.debug({ message: 'optional message' });
175
- ```
176
-
177
- logs optional message and colored JSX:
178
-
179
- ```jsx
180
- optional message
181
-
182
- <View
183
- onPress={[Function bound fn]}
184
- >
185
- <Text>Press me</Text>
186
- </View>
187
- ```
188
-
189
- #### `mapProps` option
190
-
191
- You can use the `mapProps` option to transform the props that will be printed :
192
-
193
- ```jsx
194
- render(<View style={{ backgroundColor: 'red' }} />);
195
- debug({ mapProps: ({ style, ...props }) => ({ props }) });
196
- ```
197
-
198
- This will log the rendered JSX without the `style` props.
199
-
200
- The `children` prop cannot be filtered out so the following will print all rendered components with all props but `children` filtered out.
201
-
202
- ```ts
203
- debug({ mapProps: (props) => ({}) });
204
- ```
205
-
206
- This option can be used to target specific props when debugging a query (for instance keeping only `children` prop when debugging a `getByText` query).
207
-
208
- You can also transform prop values so that they are more readable (e.g. flatten styles).
209
-
210
- ```ts
211
- import { StyleSheet } from 'react-native';
212
-
213
- debug({ mapProps : {({ style, ...props })} => ({ style : StyleSheet.flatten(style), ...props }) });
214
- ```
215
-
216
- Or remove props that have little value when debugging tests, e.g. path prop for svgs
217
-
218
- ```ts
219
- debug({ mapProps: ({ path, ...props }) => ({ ...props }) });
220
- ```
221
-
222
- #### `debug.shallow`
223
-
224
- Pretty prints shallowly rendered component passed to `render` with optional message on top.
225
-
226
- ### `toJSON`
227
-
228
- ```ts
229
- toJSON(): ReactTestRendererJSON | null
230
- ```
231
-
232
- Get the rendered component JSON representation, e.g. for snapshot testing.
233
-
234
- ### `root`
235
-
236
- ```ts
237
- root: ReactTestInstance;
238
- ```
239
-
240
- Returns the rendered root [host element](testing-env#host-and-composite-components).
241
-
242
- This API is primarily useful in component tests, as it allows you to access root host view without using `*ByTestId` queries or similar methods.
243
-
244
- ### `UNSAFE_root`
245
-
246
- ```ts
247
- UNSAFE_root: ReactTestInstance;
248
- ```
249
-
250
- Returns the rendered [composite root element](testing-env#host-and-composite-components).
251
-
252
- :::caution
253
- This API typically will return a composite view which goes against recommended testing practices. This API is primarily available for legacy test suites that rely on such testing.
254
- :::
255
-
256
- :::note
257
- This API has been previously named `container` for compatibility with [React Testing Library](https://testing-library.com/docs/react-testing-library/api#container-1). However, despite the same name, the actual behavior has been signficantly different, hence the name change to `UNSAFE_root`.
258
- :::
259
-
260
- ## `screen`
261
-
262
- ```ts
263
- let screen: RenderResult;
264
- ```
265
-
266
- Hold the value of latest render call for easier access to query and other functions returned by [`render`](#render).
267
-
268
- Its value is automatically cleared after each test by calling [`cleanup`](#cleanup). If no `render` call has been made in a given test then it holds a special object that implements `RenderResult` but throws a helpful error on each property and method access.
269
-
270
- This can also be used to build test utils that would normally require to be in render scope, either in a test file or globally for your project. For instance:
271
-
272
- ```ts
273
- // Prints the rendered components omitting all props except children.
274
- const debugText = () => screen.debug({ mapProps: (props) => ({}) });
275
- ```
276
-
277
- ## `cleanup`
278
-
279
- ```ts
280
- const cleanup: () => void;
281
- ```
282
-
283
- Unmounts React trees that were mounted with `render` and clears `screen` variable that holds latest `render` output.
284
-
285
- :::info
286
- Please note that this is done automatically if the testing framework you're using supports the `afterEach` global (like mocha, Jest, and Jasmine). If not, you will need to do manual cleanups after each test.
287
- :::
288
-
289
- For example, if you're using the `jest` testing framework, then you would need to use the `afterEach` hook like so:
290
-
291
- ```jsx
292
- import { cleanup, render } from '@testing-library/react-native/pure';
293
- import { View } from 'react-native';
294
-
295
- afterEach(cleanup);
296
-
297
- it('renders a view', () => {
298
- render(<View />);
299
- // ...
300
- });
301
- ```
302
-
303
- The `afterEach(cleanup)` call also works in `describe` blocks:
304
-
305
- ```jsx
306
- describe('when logged in', () => {
307
- afterEach(cleanup);
308
-
309
- it('renders the user', () => {
310
- render(<SiteHeader />);
311
- // ...
312
- });
313
- });
314
- ```
315
-
316
- Failing to call `cleanup` when you've called `render` could result in a memory leak and tests which are not "idempotent" (which can lead to difficult to debug errors in your tests).
317
-
318
- ## `fireEvent`
319
-
320
- ```ts
321
- function fireEvent(
322
- element: ReactTestInstance,
323
- eventName: string,
324
- ...data: Array<any>
325
- ): void {}
326
- ```
327
-
328
- :::note
329
- For common events like `press` or `type` it's recommended to use [User Event API](UserEvent.md) as it offers
330
- more realistic event simulation by emitting a sequence of events with proper event objects that mimic React Native runtime behavior.
331
-
332
- Use Fire Event for cases not supported by User Event and for triggering event handlers on composite components.
333
- :::
334
-
335
- `fireEvent` API allows you to trigger all kind of event handlers on both host and composite components. It will try to invoke a single event handler traversing the component tree bottom-up from passed element and trying to find enabled event handler named `onXxx` when `xxx` is the name of the event passed.
336
-
337
- Unlike User Event, this API does not automatically pass event object to event handler, this is responsibility of the user to construct such object.
338
-
339
- ```jsx
340
- import { render, screen, fireEvent } from '@testing-library/react-native';
341
-
342
- test('fire changeText event', () => {
343
- const onEventMock = jest.fn();
344
- render(
345
- // MyComponent renders TextInput which has a placeholder 'Enter details'
346
- // and with `onChangeText` bound to handleChangeText
347
- <MyComponent handleChangeText={onEventMock} />
348
- );
349
-
350
- fireEvent(screen.getByPlaceholderText('change'), 'onChangeText', 'ab');
351
- expect(onEventMock).toHaveBeenCalledWith('ab');
352
- });
353
- ```
354
-
355
- :::note
356
- Please note that from version `7.0` `fireEvent` performs checks that should prevent events firing on disabled elements.
357
- :::
358
-
359
- An example using `fireEvent` with native events that aren't already aliased by the `fireEvent` api.
360
-
361
- ```jsx
362
- import { TextInput, View } from 'react-native';
363
- import { fireEvent, render } from '@testing-library/react-native';
364
-
365
- const onBlurMock = jest.fn();
366
-
367
- render(
368
- <View>
369
- <TextInput placeholder="my placeholder" onBlur={onBlurMock} />
370
- </View>
371
- );
372
-
373
- // you can omit the `on` prefix
374
- fireEvent(screen.getByPlaceholderText('my placeholder'), 'blur');
375
- ```
376
-
377
- ## `fireEvent[eventName]`
378
-
379
- ```ts
380
- fireEvent[eventName](element: ReactTestInstance, ...data: Array<any>): void
381
- ```
382
-
383
- Convenience methods for common events like: `press`, `changeText`, `scroll`.
384
-
385
- ### `fireEvent.press`
386
-
387
- ```
388
- fireEvent.press: (element: ReactTestInstance, ...data: Array<any>) => void
389
- ```
390
-
391
- :::note
392
- It is recommended to use the User Event [`press()`](UserEvent.md#press) helper instead as it offers more realistic simulation of press interaction, including pressable support.
393
- :::
394
-
395
- Invokes `press` event handler on the element or parent element in the tree.
396
-
397
- ```jsx
398
- import { View, Text, TouchableOpacity } from 'react-native';
399
- import { render, screen, fireEvent } from '@testing-library/react-native';
400
-
401
- const onPressMock = jest.fn();
402
- const eventData = {
403
- nativeEvent: {
404
- pageX: 20,
405
- pageY: 30,
406
- },
407
- };
408
-
409
- render(
410
- <View>
411
- <TouchableOpacity onPress={onPressMock}>
412
- <Text>Press me</Text>
413
- </TouchableOpacity>
414
- </View>
415
- );
416
-
417
- fireEvent.press(screen.getByText('Press me'), eventData);
418
- expect(onPressMock).toHaveBeenCalledWith(eventData);
419
- ```
420
-
421
- ### `fireEvent.changeText`
422
-
423
- ```
424
- fireEvent.changeText: (element: ReactTestInstance, ...data: Array<any>) => void
425
- ```
426
-
427
- :::note
428
- It is recommended to use the User Event [`type()`](UserEvent.md#type) helper instead as it offers more realistic simulation of text change interaction, including key-by-key typing, element focus, and other editing events.
429
- :::
430
-
431
- Invokes `changeText` event handler on the element or parent element in the tree.
432
-
433
- ```jsx
434
- import { View, TextInput } from 'react-native';
435
- import { render, screen, fireEvent } from '@testing-library/react-native';
436
-
437
- const onChangeTextMock = jest.fn();
438
- const CHANGE_TEXT = 'content';
439
-
440
- render(
441
- <View>
442
- <TextInput placeholder="Enter data" onChangeText={onChangeTextMock} />
443
- </View>
444
- );
445
-
446
- fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
447
- ```
448
-
449
- ### `fireEvent.scroll`
450
-
451
- ```
452
- fireEvent.scroll: (element: ReactTestInstance, ...data: Array<any>) => void
453
- ```
454
-
455
- Invokes `scroll` event handler on the element or parent element in the tree.
456
-
457
- #### On a `ScrollView`
458
-
459
- ```jsx
460
- import { ScrollView, Text } from 'react-native';
461
- import { render, screen, fireEvent } from '@testing-library/react-native';
462
-
463
- const onScrollMock = jest.fn();
464
- const eventData = {
465
- nativeEvent: {
466
- contentOffset: {
467
- y: 200,
468
- },
469
- },
470
- };
471
-
472
- render(
473
- <ScrollView onScroll={onScrollMock}>
474
- <Text>XD</Text>
475
- </ScrollView>
476
- );
477
-
478
- fireEvent.scroll(screen.getByText('scroll-view'), eventData);
479
- ```
480
-
481
- #### On a `FlatList`
482
-
483
- ```jsx
484
- import { FlatList, View } from 'react-native';
485
- import { render, screen, fireEvent } from '@testing-library/react-native';
486
-
487
- const onEndReached = jest.fn();
488
- render(
489
- <FlatList
490
- data={Array.from({ length: 10 }, (_, key) => ({ key: `${key}` }))}
491
- renderItem={() => <View style={{ height: 500, width: 100 }} />}
492
- onEndReached={onEndReached}
493
- onEndReachedThreshold={0.2}
494
- testID="flat-list"
495
- />
496
- );
497
- const eventData = {
498
- nativeEvent: {
499
- contentOffset: {
500
- y: 500,
501
- },
502
- contentSize: {
503
- // Dimensions of the scrollable content
504
- height: 500,
505
- width: 100,
506
- },
507
- layoutMeasurement: {
508
- // Dimensions of the device
509
- height: 100,
510
- width: 100,
511
- },
512
- },
513
- };
514
-
515
- fireEvent.scroll(screen.getByTestId('flat-list'), eventData);
516
- expect(onEndReached).toHaveBeenCalled();
517
- ```
518
-
519
- :::note
520
- If you're noticing that components are not being found on a list, even after mocking a scroll event, try changing the [`initialNumToRender`](https://reactnative.dev/docs/flatlist#initialnumtorender) that you have set. If you aren't comfortable changing the code to accept this prop from the unit test, try using an e2e test that might better suit what use case you're attempting to replicate.
521
- :::
522
-
523
- ## `waitFor`
524
-
525
- - [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitFor.test.tsx)
526
-
527
- Defined as:
528
-
529
- ```jsx
530
- function waitFor<T>(
531
- expectation: () => T,
532
- { timeout: number = 1000, interval: number = 50 }
533
- ): Promise<T> {}
534
- ```
535
-
536
- Waits for a period of time for the `expectation` callback to pass. `waitFor` may run the callback a number of times until timeout is reached, as specified by the `timeout` and `interval` options. The callback must throw an error when the expectation is not met. Returning any value, including a falsy one, will be treated as meeting the expectation, and the callback result will be returned to the caller of `waitFor` function.
537
-
538
- ```tsx
539
- await waitFor(() => expect(mockFunction).toHaveBeenCalledWith()))
540
- ```
541
-
542
- `waitFor` function will be executing `expectation` callback every `interval` (default: every 50 ms) until `timeout` (default: 1000 ms) is reached. The repeated execution of callback is stopped as soon as it does not throw an error, in such case the value returned by the callback is returned to `waitFor` caller. Otherwise, when it reaches the timeout, the final error thrown by `expectation` will be re-thrown by `waitFor` to the calling code.
543
-
544
- ```tsx
545
- // ❌ `waitFor` will return immediately because callback does not throw
546
- await waitFor(() => false);
547
- ```
548
-
549
- `waitFor` is an async function so you need to `await` the result to pause test execution.
550
-
551
- ```jsx
552
- // ❌ missing `await`: `waitFor` will just return Promise that will be rejected when the timeout is reached
553
- waitFor(() => expect(1).toBe(2))
554
- ```
555
-
556
- :::note
557
- You can enforce awaiting `waitFor` by using the [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/await-async-utils.md) rule from [eslint-plugin-testing-library](https://github.com/testing-library/eslint-plugin-testing-library).
558
- :::
559
-
560
- Since `waitFor` is likely to run `expectation` callback multiple times, it is highly recommended for it [not to perform any side effects](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#performing-side-effects-in-waitfor) in `waitFor`.
561
-
562
- ```jsx
563
- await waitFor(() => {
564
- // ❌ button will be pressed on each waitFor iteration
565
- fireEvent.press(screen.getByText('press me'))
566
- expect(mockOnPress).toHaveBeenCalled()
567
- })
568
- ```
569
-
570
- :::note
571
- Avoiding side effects in `expectation` callback can be partially enforced with the [`no-wait-for-side-effects` rule](https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/no-wait-for-side-effects.md).
572
- :::
573
-
574
- It is also recommended to have a [single assertion per each `waitFor`](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#having-multiple-assertions-in-a-single-waitfor-callback) for more consistency and faster failing tests. If you want to make several assertions, then they should be in seperate `waitFor` calls. In many cases you won't actually need to wrap the second assertion in `waitFor` since the first one will do the waiting required for asynchronous change to happen.
575
-
576
- ### Using a React Native version < 0.71 with Jest fake timers
577
-
578
- :::caution
579
- When using a version of React Native < 0.71 and modern fake timers (the default for `Jest` >= 27), `waitFor` won't work (it will always timeout even if `expectation()` doesn't throw) unless you use the custom [@testing-library/react-native preset](https://github.com/callstack/react-native-testing-library#custom-jest-preset).
580
- :::
581
-
582
- `waitFor` checks whether Jest fake timers are enabled and adapts its behavior in such case. The following snippet is a simplified version of how it behaves when fake timers are enabled:
583
-
584
- ```tsx
585
- let fakeTimeRemaining = timeout;
586
- let lastError;
587
-
588
- while(fakeTimeRemaining > 0) {
589
- fakeTimeRemaining = fakeTimeRemaining - interval;
590
- jest.advanceTimersByTime(interval);
591
- try {
592
- // resolve
593
- return expectation();
594
- } catch (error) {
595
- lastError = error;
596
- }
597
- }
598
-
599
- // reject
600
- throw lastError
601
- ```
602
-
603
- In the following example we test that a function is called after 10 seconds using fake timers. Since we're using fake timers, the test won't depend on real time passing and thus be much faster and more reliable. Also we don't have to advance fake timers through Jest fake timers API because `waitFor` already does this for us.
604
-
605
- ```tsx
606
- // in component
607
- setTimeout(() => {
608
- someFunction();
609
- }, 10000)
610
-
611
- // in test
612
- jest.useFakeTimers();
613
-
614
- await waitFor(() => {
615
- expect(someFunction).toHaveBeenCalledWith();
616
- }, 10000)
617
- ```
618
-
619
- :::info
620
- In order to properly use `waitFor` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0).
621
- :::
622
-
623
- :::note
624
- If you receive warnings related to `act()` function consult our [Undestanding Act](./UnderstandingAct.md) function document.
625
- :::
626
-
627
- ## `waitForElementToBeRemoved`
628
-
629
- - [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitForElementToBeRemoved.test.tsx)
630
-
631
- Defined as:
632
-
633
- ```ts
634
- function waitForElementToBeRemoved<T>(
635
- expectation: () => T,
636
- { timeout: number = 4500, interval: number = 50 }
637
- ): Promise<T> {}
638
- ```
639
-
640
- Waits for non-deterministic periods of time until queried element is removed or times out. `waitForElementToBeRemoved` periodically calls `expectation` every `interval` milliseconds to determine whether the element has been removed or not.
641
-
642
- ```jsx
643
- import {
644
- render,
645
- screen,
646
- waitForElementToBeRemoved,
647
- } from '@testing-library/react-native';
648
-
649
- test('waiting for an Banana to be removed', async () => {
650
- render(<Banana />);
651
-
652
- await waitForElementToBeRemoved(() => screen.getByText('Banana ready'));
653
- });
654
- ```
655
-
656
- This method expects that the element is initially present in the render tree and then is removed from it. If the element is not present when you call this method it throws an error.
657
-
658
- You can use any of `getBy`, `getAllBy`, `queryBy` and `queryAllBy` queries for `expectation` parameter.
659
-
660
- :::info
661
- In order to properly use `waitForElementToBeRemoved` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0).
662
- :::
663
-
664
- :::note
665
- If you receive warnings related to `act()` function consult our [Undestanding Act](./UnderstandingAct.md) function document.
666
- :::
667
-
668
- ## `within`, `getQueriesForElement`
669
-
670
- - [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/within.test.tsx)
671
-
672
- Defined as:
673
-
674
- ```jsx
675
- function within(element: ReactTestInstance): Queries {}
676
-
677
- function getQueriesForElement(element: ReactTestInstance): Queries {}
678
- ```
679
-
680
- `within` (also available as `getQueriesForElement` alias) performs [queries](./Queries.md) scoped to given element.
681
-
682
- :::note
683
- Please note that additional `render` specific operations like `update`, `unmount`, `debug`, `toJSON` are _not_ included.
684
- :::
685
-
686
- ```jsx
687
- const detailsScreen = within(screen.getByA11yHint('Details Screen'));
688
- expect(detailsScreen.getByText('Some Text')).toBeOnTheScreen();
689
- expect(detailsScreen.getByDisplayValue('Some Value')).toBeOnTheScreen();
690
- expect(detailsScreen.queryByLabelText('Some Label')).toBeOnTheScreen();
691
- await expect(detailsScreen.findByA11yHint('Some Label')).resolves.toBeOnTheScreen();
692
- ```
693
-
694
- Use cases for scoped queries include:
695
-
696
- - queries scoped to a single item inside a FlatList containing many items
697
- - queries scoped to a single screen in tests involving screen transitions (e.g. with react-navigation)
698
-
699
- ## `queryBy*` APIs
700
-
701
- Each of the `getBy*` APIs listed in the render section above have a complimentary `queryBy*` API. The `getBy*` APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the hierarchy, then you can use the `queryBy*` API instead:
702
-
703
- ```jsx
704
- import { render, screen } from '@testing-library/react-native';
705
-
706
- render(<Form />);
707
- const submitButton = screen.queryByText('submit');
708
- expect(submitButton).not.toBeOnTheScreen(); // it doesn't exist
709
- ```
710
-
711
- ## `queryAll*` APIs
712
-
713
- Each of the query APIs have a corresponding `queryAll*` version that always returns an array of matching nodes. `getAll*` is the same but throws when the array has a length of 0.
714
-
715
- ```jsx
716
- import { render } from '@testing-library/react-native';
717
-
718
- render(<Forms />);
719
- const submitButtons = screen.queryAllByText('submit');
720
- expect(submitButtons).toHaveLength(3); // expect 3 elements
721
- ```
722
-
723
- ## `act`
724
-
725
- Useful function to help testing components that use hooks API. By default any `render`, `update`, `fireEvent`, and `waitFor` calls are wrapped by this function, so there is no need to wrap it manually. This method is re-exported from [`react-test-renderer`](https://github.com/facebook/react/blob/main/packages/react-test-renderer/src/ReactTestRenderer.js#L567]).
726
-
727
- Consult our [Undestanding Act function](./UnderstandingAct.md) document for more understanding of its intricacies.
728
-
729
- ## `renderHook`
730
-
731
- Defined as:
732
-
733
- ```ts
734
- function renderHook<Result, Props>(
735
- callback: (props?: Props) => Result,
736
- options?: RenderHookOptions<Props>
737
- ): RenderHookResult<Result, Props>;
738
- ```
739
-
740
- Renders a test component that will call the provided `callback`, including any hooks it calls, every time it renders. Returns [`RenderHookResult`](#renderhookresult-object) object, which you can interact with.
741
-
742
- ```ts
743
- import { renderHook } from '@testing-library/react-native';
744
- import { useCount } from '../useCount';
745
-
746
- it('should increment count', () => {
747
- const { result } = renderHook(() => useCount());
748
-
749
- expect(result.current.count).toBe(0);
750
- act(() => {
751
- // Note that you should wrap the calls to functions your hook returns with `act` if they trigger an update of your hook's state to ensure pending useEffects are run before your next assertion.
752
- result.current.increment();
753
- });
754
- expect(result.current.count).toBe(1);
755
- });
756
- ```
757
-
758
- ```ts
759
- // useCount.js
760
- export const useCount = () => {
761
- const [count, setCount] = useState(0);
762
- const increment = () => setCount((previousCount) => previousCount + 1);
763
-
764
- return { count, increment };
765
- };
766
- ```
767
-
768
- The `renderHook` function accepts the following arguments:
769
-
770
- ### `callback`
771
-
772
- The function that is called each `render` of the test component. This function should call one or more hooks for testing.
773
-
774
- The `props` passed into the callback will be the `initialProps` provided in the `options` to `renderHook`, unless new props are provided by a subsequent `rerender` call.
775
-
776
- ### `options` (Optional)
777
-
778
- A `RenderHookOptions<Props>` object to modify the execution of the `callback` function, containing the following properties:
779
-
780
- #### `initialProps`
781
-
782
- The initial values to pass as `props` to the `callback` function of `renderHook`. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
783
-
784
- #### `wrapper`
785
-
786
- A React component to wrap the test component in when rendering. This is usually used to add context providers from `React.createContext` for the hook to access with `useContext`.
787
-
788
- ### `RenderHookResult` object
789
-
790
- ```ts
791
- interface RenderHookResult<Result, Props> {
792
- result: { current: Result };
793
- rerender: (props: Props) => void;
794
- unmount: () => void;
795
- }
796
- ```
797
-
798
- The `renderHook` function returns an object that has the following properties:
799
-
800
- #### `result`
801
-
802
- The `current` value of the `result` will reflect the latest of whatever is returned from the `callback` passed to `renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
803
-
804
- #### `rerender`
805
-
806
- A function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
807
-
808
- #### `unmount`
809
-
810
- A function to unmount the test component. This is commonly used to trigger cleanup effects for `useEffect` hooks.
811
-
812
- ### Examples
813
-
814
- Here we present some extra examples of using `renderHook` API.
815
-
816
- #### With `initialProps`
817
-
818
- ```ts
819
- const useCount = (initialCount: number) => {
820
- const [count, setCount] = useState(initialCount);
821
- const increment = () => setCount((previousCount) => previousCount + 1);
822
-
823
- useEffect(() => {
824
- setCount(initialCount);
825
- }, [initialCount]);
826
-
827
- return { count, increment };
828
- };
829
-
830
- it('should increment count', () => {
831
- const { result, rerender } = renderHook(
832
- (initialCount: number) => useCount(initialCount),
833
- { initialProps: 1 }
834
- );
835
-
836
- expect(result.current.count).toBe(1);
837
-
838
- act(() => {
839
- result.current.increment();
840
- });
841
-
842
- expect(result.current.count).toBe(2);
843
- rerender(5);
844
- expect(result.current.count).toBe(5);
845
- });
846
- ```
847
-
848
- #### With `wrapper`
849
-
850
- ```tsx
851
- it('should use context value', () => {
852
- function Wrapper({ children }: { children: ReactNode }) {
853
- return <Context.Provider value="provided">{children}</Context.Provider>;
854
- }
855
-
856
- const { result } = renderHook(() => useHook(), { wrapper: Wrapper });
857
- // ...
858
- });
859
- ```
860
-
861
- ## Configuration
862
-
863
- ### `configure`
864
-
865
- ```ts
866
- type Config = {
867
- asyncUtilTimeout: number;
868
- defaultHidden: boolean;
869
- defaultDebugOptions: Partial<DebugOptions>;
870
- };
871
-
872
- function configure(options: Partial<Config>) {}
873
- ```
874
-
875
- #### `asyncUtilTimeout` option
876
-
877
- Default timeout, in ms, for async helper functions (`waitFor`, `waitForElementToBeRemoved`) and `findBy*` queries. Defaults to 1000 ms.
878
-
879
- #### `defaultIncludeHiddenElements` option
880
-
881
- Default value for [includeHiddenElements](Queries.md#includehiddenelements-option) query option for all queries. The default value is set to `false`, so all queries will not match [elements hidden from accessibility](#ishiddenfromaccessibility). This is because the users of the app would not be able to see such elements.
882
-
883
- This option is also available as `defaultHidden` alias for compatibility with [React Testing Library](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaulthidden).
884
-
885
- #### `defaultDebugOptions` option
886
-
887
- Default [debug options](#debug) to be used when calling `debug()`. These default options will be overridden by the ones you specify directly when calling `debug()`.
888
-
889
- ### `resetToDefaults()`
890
-
891
- ```ts
892
- function resetToDefaults() {}
893
- ```
894
-
895
- ### Environment variables
896
-
897
- #### `RNTL_SKIP_AUTO_CLEANUP`
898
-
899
- Set to `true` to disable automatic `cleanup()` after each test. It works the same as importing `react-native-testing-library/dont-cleanup-after-each` or using `react-native-testing-library/pure`.
900
-
901
- ```shell
902
- $ RNTL_SKIP_AUTO_CLEANUP=true jest
903
- ```
904
-
905
- #### `RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS`
906
-
907
- Set to `true` to disable auto-detection of fake timers. This might be useful in rare cases when you want to use non-Jest fake timers. See [issue #886](https://github.com/callstack/react-native-testing-library/issues/886) for more details.
908
-
909
- ```shell
910
- $ RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS=true jest
911
- ```
912
-
913
- ## Accessibility
914
-
915
- ### `isHiddenFromAccessibility`
916
-
917
- ```ts
918
- function isHiddenFromAccessibility(
919
- element: ReactTestInstance | null
920
- ): boolean {}
921
- ```
922
-
923
- Also available as `isInaccessible()` alias for React Testing Library compatibility.
924
-
925
- Checks if given element is hidden from assistive technology, e.g. screen readers.
926
-
927
- :::note
928
- Like [`isInaccessible`](https://testing-library.com/docs/dom-testing-library/api-accessibility/#isinaccessible) function from DOM Testing Library this function considers both accessibility elements and presentational elements (regular `View`s) to be accessible, unless they are hidden in terms of host platform.
929
-
930
- This covers only part of [ARIA notion of Accessiblity Tree](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), as ARIA excludes both hidden and presentational elements from the Accessibility Tree.
931
- :::
932
-
933
- For the scope of this function, element is inaccessible when it, or any of its ancestors, meets any of the following conditions:
934
-
935
- - it has `display: none` style
936
- - it has [`accessibilityElementsHidden`](https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios) prop set to `true`
937
- - it has [`importantForAccessibility`](https://reactnative.dev/docs/accessibility#importantforaccessibility-android) prop set to `no-hide-descendants`
938
- - it has sibling host element with [`accessibilityViewIsModal`](https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios) prop set to `true`
939
-
940
- Specifying `accessible={false}`, `accessiblityRole="none"`, or `importantForAccessibility="no"` props does not cause the element to become inaccessible.