@testing-library/react-native 12.1.1 → 12.1.3
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.
- package/.DS_Store +0 -0
- package/.codecov.yml +9 -0
- package/.eslintcache +1 -0
- package/.eslintignore +2 -0
- package/.eslintrc +19 -0
- package/.flowconfig +63 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +14 -0
- package/.github/ISSUE_TEMPLATE/question.md +9 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +10 -0
- package/.github/actions/setup-deps/action.yml +22 -0
- package/.github/actions/setup-website-deps/action.yml +22 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/deploy-website.yml +36 -0
- package/.github/workflows/example-apps.yml +25 -0
- package/.github/workflows/main.yml +103 -0
- package/.gitignore +11 -0
- package/.prettierrc.js +5 -0
- package/CODE_OF_CONDUCT.md +73 -0
- package/CONTRIBUTING.md +64 -0
- package/README.md +8 -7
- package/babel.config.js +22 -0
- package/build/act.js.map +1 -1
- package/build/cleanup.js.map +1 -1
- package/build/config.d.ts +1 -0
- package/build/config.js.map +1 -1
- package/build/fireEvent.d.ts +13 -5
- package/build/fireEvent.js +57 -48
- package/build/fireEvent.js.map +1 -1
- package/build/flush-micro-tasks.d.ts +19 -0
- package/build/flush-micro-tasks.js +36 -0
- package/build/flush-micro-tasks.js.map +1 -0
- package/build/helpers/accessiblity.js +3 -1
- package/build/helpers/accessiblity.js.map +1 -1
- package/build/helpers/component-tree.d.ts +0 -15
- package/build/helpers/component-tree.js +0 -45
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/deprecation.d.ts +1 -0
- package/build/helpers/deprecation.js +16 -0
- package/build/helpers/deprecation.js.map +1 -1
- package/build/helpers/errors.d.ts +0 -4
- package/build/helpers/errors.js +1 -25
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/findAll.js.map +1 -1
- package/build/helpers/format-default.js.map +1 -1
- package/build/helpers/format.js.map +1 -1
- package/build/helpers/host-component-names.js +4 -1
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/matchLabelText.js.map +1 -1
- package/build/helpers/pointer-events.d.ts +9 -0
- package/build/helpers/pointer-events.js +25 -0
- package/build/helpers/pointer-events.js.map +1 -0
- package/build/helpers/stringValidation.js.map +1 -1
- package/build/helpers/timers.js.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +1 -1
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.js.map +1 -1
- package/build/queries/a11yValue.js.map +1 -1
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/hintText.js.map +1 -1
- package/build/queries/labelText.js.map +1 -1
- package/build/queries/makeQueries.js.map +1 -1
- package/build/queries/placeholderText.js.map +1 -1
- package/build/queries/role.js.map +1 -1
- package/build/queries/testId.js.map +1 -1
- package/build/queries/text.js.map +1 -1
- package/build/queries/unsafeProps.js.map +1 -1
- package/build/render.d.ts +171 -12
- package/build/render.js +11 -4
- package/build/render.js.map +1 -1
- package/build/renderHook.d.ts +3 -6
- package/build/renderHook.js +4 -3
- package/build/renderHook.js.map +1 -1
- package/build/shallow.js.map +1 -1
- package/build/test-utils/events.d.ts +10 -0
- package/build/test-utils/events.js +27 -0
- package/build/test-utils/events.js.map +1 -0
- package/build/test-utils/index.d.ts +1 -0
- package/build/test-utils/index.js +17 -0
- package/build/test-utils/index.js.map +1 -0
- package/build/user-event/event-builder/common.d.ts +45 -0
- package/build/user-event/event-builder/common.js +58 -0
- package/build/user-event/event-builder/common.js.map +1 -0
- package/build/user-event/event-builder/index.d.ts +32 -0
- package/build/user-event/event-builder/index.js +12 -0
- package/build/user-event/event-builder/index.js.map +1 -0
- package/build/user-event/index.d.ts +9 -0
- package/build/user-event/index.js +16 -0
- package/build/user-event/index.js.map +1 -0
- package/build/user-event/press/constants.d.ts +2 -0
- package/build/user-event/press/constants.js +16 -0
- package/build/user-event/press/constants.js.map +1 -0
- package/build/user-event/press/index.d.ts +1 -0
- package/build/user-event/press/index.js +19 -0
- package/build/user-event/press/index.js.map +1 -0
- package/build/user-event/press/press.d.ts +7 -0
- package/build/user-event/press/press.js +106 -0
- package/build/user-event/press/press.js.map +1 -0
- package/build/user-event/press/utils/warnAboutRealTimers.d.ts +1 -0
- package/build/user-event/press/utils/warnAboutRealTimers.js +14 -0
- package/build/user-event/press/utils/warnAboutRealTimers.js.map +1 -0
- package/build/user-event/setup/index.d.ts +2 -0
- package/build/user-event/setup/index.js +13 -0
- package/build/user-event/setup/index.js.map +1 -0
- package/build/user-event/setup/setup.d.ts +39 -0
- package/build/user-event/setup/setup.js +56 -0
- package/build/user-event/setup/setup.js.map +1 -0
- package/build/user-event/type/index.d.ts +1 -0
- package/build/user-event/type/index.js +13 -0
- package/build/user-event/type/index.js.map +1 -0
- package/build/user-event/type/type.d.ts +3 -0
- package/build/user-event/type/type.js +18 -0
- package/build/user-event/type/type.js.map +1 -0
- package/build/user-event/utils/events.d.ts +9 -0
- package/build/user-event/utils/events.js +44 -0
- package/build/user-event/utils/events.js.map +1 -0
- package/build/user-event/utils/index.d.ts +2 -0
- package/build/user-event/utils/index.js +28 -0
- package/build/user-event/utils/index.js.map +1 -0
- package/build/user-event/utils/wait.d.ts +2 -0
- package/build/user-event/utils/wait.js +14 -0
- package/build/user-event/utils/wait.js.map +1 -0
- package/build/waitFor.js +3 -3
- package/build/waitFor.js.map +1 -1
- package/build/waitForElementToBeRemoved.js.map +1 -1
- package/examples/basic/.expo-shared/assets.json +4 -0
- package/examples/basic/.gitignore +14 -0
- package/examples/basic/App.tsx +20 -0
- package/examples/basic/README.md +11 -0
- package/examples/basic/__tests__/App.test.tsx +119 -0
- package/examples/basic/app.json +31 -0
- package/examples/basic/assets/adaptive-icon.png +0 -0
- package/examples/basic/assets/favicon.png +0 -0
- package/examples/basic/assets/icon.png +0 -0
- package/examples/basic/assets/splash.png +0 -0
- package/examples/basic/babel.config.js +6 -0
- package/examples/basic/components/Home.tsx +28 -0
- package/examples/basic/components/LoginForm.tsx +138 -0
- package/examples/basic/jest-setup.ts +7 -0
- package/examples/basic/jest.config.js +5 -0
- package/examples/basic/package.json +30 -0
- package/examples/basic/tsconfig.json +7 -0
- package/examples/react-navigation/README.md +14 -0
- package/examples/react-navigation/babel.config.js +4 -0
- package/examples/react-navigation/jest-setup.js +11 -0
- package/examples/react-navigation/jest.config.js +10 -0
- package/examples/react-navigation/package.json +31 -0
- package/examples/react-navigation/src/App.js +21 -0
- package/examples/react-navigation/src/DrawerNavigator.js +15 -0
- package/examples/react-navigation/src/DrawerNavigator.test.js +42 -0
- package/examples/react-navigation/src/NativeStackNavigator.js +15 -0
- package/examples/react-navigation/src/NativeStackNavigator.test.js +34 -0
- package/examples/react-navigation/src/StackNavigator.js +15 -0
- package/examples/react-navigation/src/StackNavigator.test.js +34 -0
- package/examples/react-navigation/src/TabNavigator.js +15 -0
- package/examples/react-navigation/src/TabNavigator.test.js +21 -0
- package/examples/react-navigation/src/screens/DetailsScreen.js +43 -0
- package/examples/react-navigation/src/screens/DetailsScreen.test.js +27 -0
- package/examples/react-navigation/src/screens/DrawerHomeScreen.js +26 -0
- package/examples/react-navigation/src/screens/HomeScreen.js +48 -0
- package/examples/react-navigation/src/screens/SettingsScreen.js +20 -0
- package/examples/react-navigation/src/test-utils.js +12 -0
- package/examples/redux/App.js +27 -0
- package/examples/redux/actions/todoActions.js +25 -0
- package/examples/redux/babel.config.js +6 -0
- package/examples/redux/components/AddTodo.js +73 -0
- package/examples/redux/components/AddTodo.test.js +27 -0
- package/examples/redux/components/TodoElem.js +25 -0
- package/examples/redux/components/TodoList.js +29 -0
- package/examples/redux/components/TodoList.test.js +34 -0
- package/examples/redux/index.js +8 -0
- package/examples/redux/jest-setup.js +2 -0
- package/examples/redux/jest.config.js +4 -0
- package/examples/redux/package.json +23 -0
- package/examples/redux/reducers/index.js +6 -0
- package/examples/redux/reducers/todoReducer.js +27 -0
- package/examples/redux/store.js +10 -0
- package/examples/redux/test-utils.js +11 -0
- package/experiments-app/.expo/README.md +15 -0
- package/experiments-app/.expo/devices.json +3 -0
- package/experiments-app/.expo/packager-info.json +9 -0
- package/experiments-app/.expo/settings.json +9 -0
- package/experiments-app/.gitignore +17 -0
- package/experiments-app/.prettierrc.js +5 -0
- package/experiments-app/app.json +30 -0
- package/experiments-app/assets/adaptive-icon.png +0 -0
- package/experiments-app/assets/favicon.png +0 -0
- package/experiments-app/assets/icon.png +0 -0
- package/experiments-app/assets/splash.png +0 -0
- package/experiments-app/babel.config.js +6 -0
- package/experiments-app/index.js +4 -0
- package/experiments-app/package.json +31 -0
- package/experiments-app/src/App.tsx +31 -0
- package/experiments-app/src/MainScreen.tsx +51 -0
- package/experiments-app/src/experiments.ts +17 -0
- package/experiments-app/src/screens/TextInputEventPropagation.tsx +54 -0
- package/experiments-app/src/screens/TextInputEvents.tsx +50 -0
- package/experiments-app/src/utils/helpers.ts +8 -0
- package/experiments-app/tsconfig.json +6 -0
- package/experiments-app/yarn.lock +6913 -0
- package/flow-typed/npm/jest_v26.x.x.js +1218 -0
- package/flow-typed/npm/react-test-renderer_v16.x.x.js +81 -0
- package/jest-setup.ts +10 -0
- package/package.json +6 -6
- package/renovate.json +19 -0
- package/scripts/test_react_17 +12 -0
- package/src/__tests__/__snapshots__/render-debug.test.tsx.snap +548 -0
- package/src/__tests__/__snapshots__/render.test.tsx.snap +39 -0
- package/src/__tests__/act.test.tsx +52 -0
- package/src/__tests__/auto-cleanup-skip.test.tsx +39 -0
- package/src/__tests__/auto-cleanup.test.tsx +50 -0
- package/src/__tests__/cleanup.test.tsx +26 -0
- package/src/__tests__/config.test.ts +55 -0
- package/src/__tests__/fireEvent-textInput.test.tsx +154 -0
- package/src/__tests__/fireEvent.test.tsx +485 -0
- package/src/__tests__/host-component-names.test.tsx +109 -0
- package/src/__tests__/host-text-nesting.test.tsx +90 -0
- package/src/__tests__/jest-native.test.tsx +84 -0
- package/src/__tests__/questionsBoard.test.tsx +62 -0
- package/src/__tests__/react-native-api.test.tsx +126 -0
- package/src/__tests__/render-debug.test.tsx +207 -0
- package/src/__tests__/render-stringValidation.test.tsx +157 -0
- package/src/__tests__/render.test.tsx +256 -0
- package/src/__tests__/renderHook.test.tsx +114 -0
- package/src/__tests__/screen.test.tsx +66 -0
- package/src/__tests__/timerUtils.ts +7 -0
- package/src/__tests__/timers.test.ts +27 -0
- package/src/__tests__/waitFor.test.tsx +327 -0
- package/src/__tests__/waitForElementToBeRemoved.test.tsx +151 -0
- package/src/__tests__/within.test.tsx +96 -0
- package/src/act.ts +86 -0
- package/src/cleanup.ts +15 -0
- package/src/config.ts +72 -0
- package/src/fireEvent.ts +163 -0
- package/src/flush-micro-tasks.ts +30 -0
- package/src/helpers/__tests__/accessiblity.test.tsx +373 -0
- package/src/helpers/__tests__/component-tree.test.tsx +226 -0
- package/src/helpers/__tests__/format-default.tsx +114 -0
- package/src/helpers/__tests__/getTextContent.test.tsx +49 -0
- package/src/helpers/__tests__/includeHiddenElements.test.tsx +39 -0
- package/src/helpers/__tests__/query-name.test.ts +10 -0
- package/src/helpers/__tests__/timers.test.ts +8 -0
- package/src/helpers/accessiblity.ts +108 -0
- package/src/helpers/component-tree.ts +89 -0
- package/src/helpers/debugDeep.ts +27 -0
- package/src/helpers/debugShallow.ts +22 -0
- package/src/helpers/deprecation.ts +53 -0
- package/src/helpers/errors.ts +66 -0
- package/src/helpers/filterNodeByType.ts +7 -0
- package/src/helpers/findAll.ts +68 -0
- package/src/helpers/format-default.ts +72 -0
- package/src/helpers/format.ts +47 -0
- package/src/helpers/getTextContent.ts +20 -0
- package/src/helpers/host-component-names.tsx +67 -0
- package/src/helpers/matchers/__tests__/matchArrayValue.test.ts +34 -0
- package/src/helpers/matchers/__tests__/matchObject.test.ts +37 -0
- package/src/helpers/matchers/__tests__/matchStringValue.test.ts +15 -0
- package/src/helpers/matchers/accessibilityState.ts +48 -0
- package/src/helpers/matchers/accessibilityValue.ts +24 -0
- package/src/helpers/matchers/matchArrayProp.ts +21 -0
- package/src/helpers/matchers/matchLabelText.ts +51 -0
- package/src/helpers/matchers/matchObjectProp.ts +25 -0
- package/src/helpers/matchers/matchStringProp.ts +23 -0
- package/src/helpers/matchers/matchTextContent.ts +20 -0
- package/src/helpers/pointer-events.ts +27 -0
- package/src/helpers/query-name.ts +4 -0
- package/src/helpers/stringValidation.ts +36 -0
- package/src/helpers/timers.ts +98 -0
- package/src/index.ts +33 -0
- package/src/matches.ts +49 -0
- package/src/pure.ts +25 -0
- package/src/queries/__tests__/a11yState.test.tsx +439 -0
- package/src/queries/__tests__/a11yValue.test.tsx +309 -0
- package/src/queries/__tests__/displayValue.test.tsx +221 -0
- package/src/queries/__tests__/hintText.test.tsx +177 -0
- package/src/queries/__tests__/labelText.test.tsx +242 -0
- package/src/queries/__tests__/makeQueries.test.tsx +235 -0
- package/src/queries/__tests__/placeholderText.test.tsx +136 -0
- package/src/queries/__tests__/role-value.test.tsx +176 -0
- package/src/queries/__tests__/role.test.tsx +824 -0
- package/src/queries/__tests__/testId.test.tsx +200 -0
- package/src/queries/__tests__/text.test.tsx +556 -0
- package/src/queries/a11yState.ts +131 -0
- package/src/queries/a11yValue.ts +131 -0
- package/src/queries/displayValue.ts +78 -0
- package/src/queries/hintText.ts +112 -0
- package/src/queries/labelText.ts +59 -0
- package/src/queries/makeQueries.ts +255 -0
- package/src/queries/options.ts +14 -0
- package/src/queries/placeholderText.ts +79 -0
- package/src/queries/role.ts +132 -0
- package/src/queries/testId.ts +71 -0
- package/src/queries/text.ts +66 -0
- package/src/queries/unsafeProps.ts +76 -0
- package/src/queries/unsafeType.ts +73 -0
- package/src/react-versions.ts +11 -0
- package/src/render-act.ts +19 -0
- package/src/render.tsx +183 -0
- package/src/renderHook.tsx +56 -0
- package/src/screen.ts +123 -0
- package/src/shallow.ts +18 -0
- package/src/test-utils/events.ts +24 -0
- package/src/test-utils/index.ts +1 -0
- package/src/user-event/event-builder/common.ts +50 -0
- package/src/user-event/event-builder/index.ts +5 -0
- package/src/user-event/index.ts +14 -0
- package/src/user-event/press/__tests__/longPress.real-timers.test.tsx +115 -0
- package/src/user-event/press/__tests__/longPress.test.tsx +157 -0
- package/src/user-event/press/__tests__/press.real-timers.test.tsx +318 -0
- package/src/user-event/press/__tests__/press.test.tsx +422 -0
- package/src/user-event/press/constants.ts +7 -0
- package/src/user-event/press/index.ts +1 -0
- package/src/user-event/press/press.ts +134 -0
- package/src/user-event/press/utils/warnAboutRealTimers.ts +6 -0
- package/src/user-event/setup/index.ts +2 -0
- package/src/user-event/setup/setup.ts +93 -0
- package/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap +26 -0
- package/src/user-event/type/__tests__/type.test.tsx +63 -0
- package/src/user-event/type/index.ts +1 -0
- package/src/user-event/type/type.ts +20 -0
- package/src/user-event/utils/__tests__/wait.test.ts +63 -0
- package/src/user-event/utils/events.ts +54 -0
- package/src/user-event/utils/index.ts +2 -0
- package/src/user-event/utils/wait.ts +15 -0
- package/src/waitFor.ts +228 -0
- package/src/waitForElementToBeRemoved.ts +42 -0
- package/src/within.ts +30 -0
- package/tsconfig.json +17 -0
- package/tsconfig.release.json +8 -0
- package/website/.gitignore +20 -0
- package/website/README.md +33 -0
- package/website/docker/.dockerignore +3 -0
- package/website/docker/Dockerfile +9 -0
- package/website/docker/docker-compose.yml +11 -0
- package/website/docs/API.md +946 -0
- package/website/docs/EslintPLluginTestingLibrary.md +28 -0
- package/website/docs/FAQ.md +44 -0
- package/website/docs/GettingStarted.md +100 -0
- package/website/docs/HowShouldIQuery.md +21 -0
- package/website/docs/MigrationV11.md +64 -0
- package/website/docs/MigrationV12.md +67 -0
- package/website/docs/MigrationV2.md +126 -0
- package/website/docs/MigrationV7.md +119 -0
- package/website/docs/MigrationV9.md +67 -0
- package/website/docs/Queries.md +567 -0
- package/website/docs/ReactNavigation.md +371 -0
- package/website/docs/ReduxIntegration.md +137 -0
- package/website/docs/TestingEnvironment.md +154 -0
- package/website/docs/Troubleshooting.md +44 -0
- package/website/docs/UnderstandingAct.md +227 -0
- package/website/docs/UserEvent.md +66 -0
- package/website/docusaurus.config.js +114 -0
- package/website/package.json +31 -0
- package/website/sidebars.js +20 -0
- package/website/src/components/Feature.js +31 -0
- package/website/src/css/custom.css +13 -0
- package/website/src/css/index.module.css +77 -0
- package/website/src/pages/index.js +82 -0
- package/website/static/.nojekyll +0 -0
- package/website/static/css/custom.css +28 -0
- package/website/static/img/hit.png +0 -0
- package/website/static/img/locomotive.png +0 -0
- package/website/static/img/owl.png +0 -0
- package/website/static/img/tools.png +0 -0
- package/website/yarn.lock +7669 -0
- package/yarn.lock +7765 -0
- package/build/flushMicroTasks.d.ts +0 -5
- package/build/flushMicroTasks.js +0 -17
- package/build/flushMicroTasks.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`toJSON renders host output 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
accessibilityState={
|
|
6
|
+
{
|
|
7
|
+
"busy": undefined,
|
|
8
|
+
"checked": undefined,
|
|
9
|
+
"disabled": undefined,
|
|
10
|
+
"expanded": undefined,
|
|
11
|
+
"selected": undefined,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
accessibilityValue={
|
|
15
|
+
{
|
|
16
|
+
"max": undefined,
|
|
17
|
+
"min": undefined,
|
|
18
|
+
"now": undefined,
|
|
19
|
+
"text": undefined,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
accessible={true}
|
|
23
|
+
collapsable={false}
|
|
24
|
+
focusable={true}
|
|
25
|
+
onBlur={[Function]}
|
|
26
|
+
onClick={[Function]}
|
|
27
|
+
onFocus={[Function]}
|
|
28
|
+
onResponderGrant={[Function]}
|
|
29
|
+
onResponderMove={[Function]}
|
|
30
|
+
onResponderRelease={[Function]}
|
|
31
|
+
onResponderTerminate={[Function]}
|
|
32
|
+
onResponderTerminationRequest={[Function]}
|
|
33
|
+
onStartShouldSetResponder={[Function]}
|
|
34
|
+
>
|
|
35
|
+
<Text>
|
|
36
|
+
press me
|
|
37
|
+
</Text>
|
|
38
|
+
</View>
|
|
39
|
+
`;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
import act from '../act';
|
|
4
|
+
import render from '../render';
|
|
5
|
+
import fireEvent from '../fireEvent';
|
|
6
|
+
|
|
7
|
+
type UseEffectProps = { callback(): void };
|
|
8
|
+
const UseEffect = ({ callback }: UseEffectProps) => {
|
|
9
|
+
React.useEffect(callback);
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Counter = () => {
|
|
14
|
+
const [count, setCount] = React.useState(0);
|
|
15
|
+
|
|
16
|
+
const text = `Total count: ${count}`;
|
|
17
|
+
return <Text onPress={() => setCount(count + 1)}>{text}</Text>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
test('render should trigger useEffect', () => {
|
|
21
|
+
const effectCallback = jest.fn();
|
|
22
|
+
render(<UseEffect callback={effectCallback} />);
|
|
23
|
+
|
|
24
|
+
expect(effectCallback).toHaveBeenCalledTimes(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('update should trigger useEffect', () => {
|
|
28
|
+
const effectCallback = jest.fn();
|
|
29
|
+
const { update } = render(<UseEffect callback={effectCallback} />);
|
|
30
|
+
update(<UseEffect callback={effectCallback} />);
|
|
31
|
+
|
|
32
|
+
expect(effectCallback).toHaveBeenCalledTimes(2);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('fireEvent should trigger useState', () => {
|
|
36
|
+
const { getByText } = render(<Counter />);
|
|
37
|
+
const counter = getByText(/Total count/i);
|
|
38
|
+
|
|
39
|
+
expect(counter.props.children).toEqual('Total count: 0');
|
|
40
|
+
fireEvent.press(counter);
|
|
41
|
+
expect(counter.props.children).toEqual('Total count: 1');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should be able to not await act', async () => {
|
|
45
|
+
const result = act(() => {});
|
|
46
|
+
expect(result).toHaveProperty('then');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should be able to await act', async () => {
|
|
50
|
+
const result = await act(async () => {});
|
|
51
|
+
expect(result).toBe(undefined);
|
|
52
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
let render: (element: React.ReactElement) => void;
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
process.env.RNTL_SKIP_AUTO_CLEANUP = 'true';
|
|
7
|
+
const rntl = require('..');
|
|
8
|
+
render = rntl.render;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
let isMounted = false;
|
|
12
|
+
|
|
13
|
+
class Test extends React.Component<{ onUnmount?(): void }> {
|
|
14
|
+
componentDidMount() {
|
|
15
|
+
isMounted = true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
componentWillUnmount() {
|
|
19
|
+
isMounted = false;
|
|
20
|
+
if (this.props.onUnmount) {
|
|
21
|
+
this.props.onUnmount();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return <View />;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// This just verifies that by importing RNTL in pure mode in an environment which supports
|
|
30
|
+
// afterEach (like jest) we won't get automatic cleanup between tests.
|
|
31
|
+
test('component is mounted, but not umounted before test ends', () => {
|
|
32
|
+
const fn = jest.fn();
|
|
33
|
+
render(<Test onUnmount={fn} />);
|
|
34
|
+
expect(fn).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('component is NOT automatically umounted after first test ends', () => {
|
|
38
|
+
expect(isMounted).toEqual(true);
|
|
39
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { render } from '..';
|
|
4
|
+
|
|
5
|
+
let isMounted = false;
|
|
6
|
+
|
|
7
|
+
class Test extends React.Component<{ onUnmount?(): void }> {
|
|
8
|
+
componentDidMount() {
|
|
9
|
+
isMounted = true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
componentWillUnmount() {
|
|
13
|
+
isMounted = false;
|
|
14
|
+
if (this.props.onUnmount) {
|
|
15
|
+
this.props.onUnmount();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
return <View />;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
jest.useRealTimers();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// This just verifies that by importing RNTL in an environment which supports afterEach (like jest)
|
|
28
|
+
// we'll get automatic cleanup between tests.
|
|
29
|
+
test('component is mounted, but not umounted before test ends', () => {
|
|
30
|
+
const fn = jest.fn();
|
|
31
|
+
render(<Test onUnmount={fn} />);
|
|
32
|
+
expect(isMounted).toEqual(true);
|
|
33
|
+
expect(fn).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('component is automatically umounted after first test ends', () => {
|
|
37
|
+
expect(isMounted).toEqual(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('does not time out with legacy fake timers', () => {
|
|
41
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
42
|
+
render(<Test />);
|
|
43
|
+
expect(isMounted).toEqual(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('does not time out with fake timers', () => {
|
|
47
|
+
jest.useFakeTimers();
|
|
48
|
+
render(<Test />);
|
|
49
|
+
expect(isMounted).toEqual(true);
|
|
50
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { cleanup, render } from '../pure';
|
|
5
|
+
|
|
6
|
+
class Test extends React.Component<{ onUnmount: () => void }> {
|
|
7
|
+
componentWillUnmount() {
|
|
8
|
+
if (this.props.onUnmount) {
|
|
9
|
+
this.props.onUnmount();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
render() {
|
|
13
|
+
return <View />;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('cleanup', () => {
|
|
18
|
+
const fn = jest.fn();
|
|
19
|
+
|
|
20
|
+
render(<Test onUnmount={fn} />);
|
|
21
|
+
render(<Test onUnmount={fn} />);
|
|
22
|
+
expect(fn).not.toHaveBeenCalled();
|
|
23
|
+
|
|
24
|
+
cleanup();
|
|
25
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
26
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getConfig,
|
|
3
|
+
configure,
|
|
4
|
+
resetToDefaults,
|
|
5
|
+
configureInternal,
|
|
6
|
+
} from '../config';
|
|
7
|
+
|
|
8
|
+
test('getConfig() returns existing configuration', () => {
|
|
9
|
+
expect(getConfig().asyncUtilTimeout).toEqual(1000);
|
|
10
|
+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('configure() overrides existing config values', () => {
|
|
14
|
+
configure({ asyncUtilTimeout: 5000 });
|
|
15
|
+
configure({ defaultDebugOptions: { message: 'debug message' } });
|
|
16
|
+
expect(getConfig()).toEqual({
|
|
17
|
+
asyncUtilTimeout: 5000,
|
|
18
|
+
defaultDebugOptions: { message: 'debug message' },
|
|
19
|
+
defaultIncludeHiddenElements: false,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('resetToDefaults() resets config to defaults', () => {
|
|
24
|
+
configure({
|
|
25
|
+
asyncUtilTimeout: 5000,
|
|
26
|
+
defaultIncludeHiddenElements: true,
|
|
27
|
+
});
|
|
28
|
+
expect(getConfig().asyncUtilTimeout).toEqual(5000);
|
|
29
|
+
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
|
|
30
|
+
|
|
31
|
+
resetToDefaults();
|
|
32
|
+
expect(getConfig().asyncUtilTimeout).toEqual(1000);
|
|
33
|
+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('resetToDefaults() resets internal config to defaults', () => {
|
|
37
|
+
configureInternal({
|
|
38
|
+
hostComponentNames: { text: 'A', textInput: 'A', switch: 'A' },
|
|
39
|
+
});
|
|
40
|
+
expect(getConfig().hostComponentNames).toEqual({
|
|
41
|
+
text: 'A',
|
|
42
|
+
textInput: 'A',
|
|
43
|
+
switch: 'A',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
resetToDefaults();
|
|
47
|
+
expect(getConfig().hostComponentNames).toBe(undefined);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('configure handles alias option defaultHidden', () => {
|
|
51
|
+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
|
|
52
|
+
|
|
53
|
+
configure({ defaultHidden: true });
|
|
54
|
+
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
|
|
55
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, TextInput, TextInputProps } from 'react-native';
|
|
3
|
+
import { render, fireEvent } from '..';
|
|
4
|
+
|
|
5
|
+
function WrappedTextInput(props: TextInputProps) {
|
|
6
|
+
return <TextInput {...props} />;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function DoubleWrappedTextInput(props: TextInputProps) {
|
|
10
|
+
return <WrappedTextInput {...props} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const layoutEvent = { nativeEvent: { layout: { width: 100, height: 100 } } };
|
|
14
|
+
|
|
15
|
+
test('should fire only non-touch-related events on non-editable TextInput', () => {
|
|
16
|
+
const onFocus = jest.fn();
|
|
17
|
+
const onChangeText = jest.fn();
|
|
18
|
+
const onSubmitEditing = jest.fn();
|
|
19
|
+
const onLayout = jest.fn();
|
|
20
|
+
|
|
21
|
+
const view = render(
|
|
22
|
+
<TextInput
|
|
23
|
+
editable={false}
|
|
24
|
+
testID="subject"
|
|
25
|
+
onFocus={onFocus}
|
|
26
|
+
onChangeText={onChangeText}
|
|
27
|
+
onSubmitEditing={onSubmitEditing}
|
|
28
|
+
onLayout={onLayout}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const subject = view.getByTestId('subject');
|
|
33
|
+
fireEvent(subject, 'focus');
|
|
34
|
+
fireEvent.changeText(subject, 'Text');
|
|
35
|
+
fireEvent(subject, 'submitEditing', { nativeEvent: { text: 'Text' } });
|
|
36
|
+
fireEvent(subject, 'layout', layoutEvent);
|
|
37
|
+
|
|
38
|
+
expect(onFocus).not.toHaveBeenCalled();
|
|
39
|
+
expect(onChangeText).not.toHaveBeenCalled();
|
|
40
|
+
expect(onSubmitEditing).not.toHaveBeenCalled();
|
|
41
|
+
expect(onLayout).toHaveBeenCalledWith(layoutEvent);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should fire only non-touch-related events on non-editable TextInput with nested Text', () => {
|
|
45
|
+
const onFocus = jest.fn();
|
|
46
|
+
const onChangeText = jest.fn();
|
|
47
|
+
const onSubmitEditing = jest.fn();
|
|
48
|
+
const onLayout = jest.fn();
|
|
49
|
+
|
|
50
|
+
const view = render(
|
|
51
|
+
<TextInput
|
|
52
|
+
editable={false}
|
|
53
|
+
testID="subject"
|
|
54
|
+
onFocus={onFocus}
|
|
55
|
+
onChangeText={onChangeText}
|
|
56
|
+
onSubmitEditing={onSubmitEditing}
|
|
57
|
+
onLayout={onLayout}
|
|
58
|
+
>
|
|
59
|
+
<Text>Nested Text</Text>
|
|
60
|
+
</TextInput>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const subject = view.getByText('Nested Text');
|
|
64
|
+
fireEvent(subject, 'focus');
|
|
65
|
+
fireEvent(subject, 'onFocus');
|
|
66
|
+
fireEvent.changeText(subject, 'Text');
|
|
67
|
+
fireEvent(subject, 'submitEditing', { nativeEvent: { text: 'Text' } });
|
|
68
|
+
fireEvent(subject, 'onSubmitEditing', { nativeEvent: { text: 'Text' } });
|
|
69
|
+
fireEvent(subject, 'layout', layoutEvent);
|
|
70
|
+
fireEvent(subject, 'onLayout', layoutEvent);
|
|
71
|
+
|
|
72
|
+
expect(onFocus).not.toHaveBeenCalled();
|
|
73
|
+
expect(onChangeText).not.toHaveBeenCalled();
|
|
74
|
+
expect(onSubmitEditing).not.toHaveBeenCalled();
|
|
75
|
+
expect(onLayout).toHaveBeenCalledTimes(2);
|
|
76
|
+
expect(onLayout).toHaveBeenCalledWith(layoutEvent);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Historically there were problems with custom TextInput wrappers, as they
|
|
81
|
+
* could creat a hierarchy of three or more composite text input views with
|
|
82
|
+
* very similar event props.
|
|
83
|
+
*
|
|
84
|
+
* Typical hierarchy would be:
|
|
85
|
+
* - User composite TextInput
|
|
86
|
+
* - UI library composite TextInput
|
|
87
|
+
* - RN composite TextInput
|
|
88
|
+
* - RN host TextInput
|
|
89
|
+
*
|
|
90
|
+
* Previous implementation of fireEvent only checked `editable` prop for
|
|
91
|
+
* RN TextInputs, both host & composite but did not check on the UI library or
|
|
92
|
+
* user composite TextInput level, hence invoking the event handlers that
|
|
93
|
+
* should be blocked by `editable={false}` prop.
|
|
94
|
+
*/
|
|
95
|
+
test('should fire only non-touch-related events on non-editable wrapped TextInput', () => {
|
|
96
|
+
const onFocus = jest.fn();
|
|
97
|
+
const onChangeText = jest.fn();
|
|
98
|
+
const onSubmitEditing = jest.fn();
|
|
99
|
+
const onLayout = jest.fn();
|
|
100
|
+
|
|
101
|
+
const view = render(
|
|
102
|
+
<WrappedTextInput
|
|
103
|
+
editable={false}
|
|
104
|
+
testID="subject"
|
|
105
|
+
onFocus={onFocus}
|
|
106
|
+
onChangeText={onChangeText}
|
|
107
|
+
onSubmitEditing={onSubmitEditing}
|
|
108
|
+
onLayout={onLayout}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const subject = view.getByTestId('subject');
|
|
113
|
+
fireEvent(subject, 'focus');
|
|
114
|
+
fireEvent.changeText(subject, 'Text');
|
|
115
|
+
fireEvent(subject, 'submitEditing', { nativeEvent: { text: 'Text' } });
|
|
116
|
+
fireEvent(subject, 'layout', layoutEvent);
|
|
117
|
+
|
|
118
|
+
expect(onFocus).not.toHaveBeenCalled();
|
|
119
|
+
expect(onChangeText).not.toHaveBeenCalled();
|
|
120
|
+
expect(onSubmitEditing).not.toHaveBeenCalled();
|
|
121
|
+
expect(onLayout).toHaveBeenCalledWith(layoutEvent);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Ditto testing for even deeper hierarchy of TextInput wrappers.
|
|
126
|
+
*/
|
|
127
|
+
test('should fire only non-touch-related events on non-editable double wrapped TextInput', () => {
|
|
128
|
+
const onFocus = jest.fn();
|
|
129
|
+
const onChangeText = jest.fn();
|
|
130
|
+
const onSubmitEditing = jest.fn();
|
|
131
|
+
const onLayout = jest.fn();
|
|
132
|
+
|
|
133
|
+
const view = render(
|
|
134
|
+
<DoubleWrappedTextInput
|
|
135
|
+
editable={false}
|
|
136
|
+
testID="subject"
|
|
137
|
+
onFocus={onFocus}
|
|
138
|
+
onChangeText={onChangeText}
|
|
139
|
+
onSubmitEditing={onSubmitEditing}
|
|
140
|
+
onLayout={onLayout}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const subject = view.getByTestId('subject');
|
|
145
|
+
fireEvent(subject, 'focus');
|
|
146
|
+
fireEvent.changeText(subject, 'Text');
|
|
147
|
+
fireEvent(subject, 'submitEditing', { nativeEvent: { text: 'Text' } });
|
|
148
|
+
fireEvent(subject, 'layout', layoutEvent);
|
|
149
|
+
|
|
150
|
+
expect(onFocus).not.toHaveBeenCalled();
|
|
151
|
+
expect(onChangeText).not.toHaveBeenCalled();
|
|
152
|
+
expect(onSubmitEditing).not.toHaveBeenCalled();
|
|
153
|
+
expect(onLayout).toHaveBeenCalledWith(layoutEvent);
|
|
154
|
+
});
|