@testing-library/react-native 12.2.1 → 12.3.0
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/build/config.d.ts +1 -0
- package/build/config.js.map +1 -1
- package/build/fireEvent.js +2 -1
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/accessiblity.d.ts +7 -0
- package/build/helpers/accessiblity.js +73 -2
- package/build/helpers/accessiblity.js.map +1 -1
- package/build/helpers/component-tree.d.ts +7 -0
- package/build/helpers/component-tree.js +18 -0
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/format-default.d.ts +1 -2
- package/build/helpers/format-default.js +22 -13
- package/build/helpers/format-default.js.map +1 -1
- package/build/helpers/format.js +1 -4
- package/build/helpers/format.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +5 -0
- package/build/helpers/host-component-names.js +13 -1
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/accessibilityState.js +3 -3
- package/build/helpers/matchers/accessibilityState.js.map +1 -1
- package/build/helpers/matchers/accessibilityValue.js +3 -2
- package/build/helpers/matchers/accessibilityValue.js.map +1 -1
- package/build/helpers/matchers/matchLabelText.d.ts +1 -1
- package/build/helpers/matchers/matchLabelText.js +5 -8
- package/build/helpers/matchers/matchLabelText.js.map +1 -1
- package/build/helpers/matchers/matchTextContent.js +2 -2
- package/build/helpers/matchers/matchTextContent.js.map +1 -1
- package/build/helpers/{getTextContent.js → text-content.js} +1 -1
- package/build/helpers/text-content.js.map +1 -0
- package/build/helpers/text-input.d.ts +3 -0
- package/build/helpers/text-input.js +21 -0
- package/build/helpers/text-input.js.map +1 -0
- package/build/matchers/extend-expect.d.js +2 -0
- package/build/matchers/extend-expect.d.js.map +1 -0
- package/build/matchers/extend-expect.d.ts +2 -0
- package/build/matchers/extend-expect.js +26 -0
- package/build/matchers/extend-expect.js.map +1 -0
- package/build/matchers/index.d.ts +9 -0
- package/build/matchers/index.js +75 -0
- package/build/matchers/index.js.map +1 -0
- package/build/matchers/to-be-checked.d.ts +6 -0
- package/build/matchers/to-be-checked.js +31 -0
- package/build/matchers/to-be-checked.js.map +1 -0
- package/build/matchers/to-be-disabled.d.ts +10 -0
- package/build/matchers/to-be-disabled.js +52 -0
- package/build/matchers/to-be-disabled.js.map +1 -0
- package/build/matchers/to-be-empty-element.d.ts +6 -0
- package/build/matchers/to-be-empty-element.js +20 -0
- package/build/matchers/to-be-empty-element.js.map +1 -0
- package/build/matchers/to-be-on-the-screen.d.ts +6 -0
- package/build/matchers/to-be-on-the-screen.js +29 -0
- package/build/matchers/to-be-on-the-screen.js.map +1 -0
- package/build/matchers/to-be-partially-checked.d.ts +6 -0
- package/build/matchers/to-be-partially-checked.js +28 -0
- package/build/matchers/to-be-partially-checked.js.map +1 -0
- package/build/matchers/to-be-visible.d.ts +6 -0
- package/build/matchers/to-be-visible.js +56 -0
- package/build/matchers/to-be-visible.js.map +1 -0
- package/build/matchers/to-have-display-value.d.ts +7 -0
- package/build/matchers/to-have-display-value.js +26 -0
- package/build/matchers/to-have-display-value.js.map +1 -0
- package/build/matchers/to-have-prop.d.ts +6 -0
- package/build/matchers/to-have-prop.js +35 -0
- package/build/matchers/to-have-prop.js.map +1 -0
- package/build/matchers/to-have-text-content.d.ts +7 -0
- package/build/matchers/to-have-text-content.js +21 -0
- package/build/matchers/to-have-text-content.js.map +1 -0
- package/build/matchers/utils.d.ts +18 -0
- package/build/matchers/utils.js +90 -0
- package/build/matchers/utils.js.map +1 -0
- package/build/matches.d.ts +1 -1
- package/build/matches.js.map +1 -1
- package/build/queries/displayValue.js +4 -3
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/labelText.js +2 -2
- package/build/queries/labelText.js.map +1 -1
- package/build/queries/role.js +1 -1
- package/build/queries/role.js.map +1 -1
- package/build/render.d.ts +12 -48
- package/build/user-event/clear.js +2 -1
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/press/press.js +2 -1
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/type/type.js +2 -1
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/index.d.ts +0 -1
- package/build/user-event/utils/index.js +0 -11
- package/build/user-event/utils/index.js.map +1 -1
- package/package.json +6 -23
- package/.DS_Store +0 -0
- package/.codecov.yml +0 -9
- package/.eslintcache +0 -1
- package/.eslintignore +0 -3
- package/.eslintrc +0 -19
- package/.flowconfig +0 -63
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
- package/.github/ISSUE_TEMPLATE/question.md +0 -9
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
- package/.github/actions/setup-deps/action.yml +0 -22
- package/.github/actions/setup-website-deps/action.yml +0 -22
- package/.github/dependabot.yml +0 -10
- package/.github/workflows/deploy-website.yml +0 -36
- package/.github/workflows/example-apps.yml +0 -25
- package/.github/workflows/main.yml +0 -103
- package/.gitignore +0 -11
- package/.prettierrc.js +0 -5
- package/CODE_OF_CONDUCT.md +0 -73
- package/CONTRIBUTING.md +0 -64
- package/babel.config.js +0 -22
- package/build/helpers/getTextContent.js.map +0 -1
- package/build/user-event/utils/host-components.d.ts +0 -2
- package/build/user-event/utils/host-components.js +0 -11
- package/build/user-event/utils/host-components.js.map +0 -1
- package/examples/basic/.expo/README.md +0 -15
- package/examples/basic/.expo/packager-info.json +0 -4
- package/examples/basic/.expo/settings.json +0 -10
- package/examples/basic/.expo-shared/assets.json +0 -4
- package/examples/basic/.gitignore +0 -14
- package/examples/basic/App.tsx +0 -20
- package/examples/basic/README.md +0 -11
- package/examples/basic/__tests__/App.test.tsx +0 -137
- package/examples/basic/app.json +0 -31
- 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 +0 -6
- package/examples/basic/components/Home.tsx +0 -28
- package/examples/basic/components/LoginForm.tsx +0 -138
- package/examples/basic/jest-setup.ts +0 -7
- package/examples/basic/jest.config.js +0 -5
- package/examples/basic/package.json +0 -30
- package/examples/basic/tsconfig.json +0 -7
- package/examples/basic/yarn.lock +0 -7499
- package/examples/react-navigation/README.md +0 -16
- package/examples/react-navigation/babel.config.js +0 -4
- package/examples/react-navigation/jest-setup.js +0 -11
- package/examples/react-navigation/jest.config.js +0 -10
- package/examples/react-navigation/package.json +0 -31
- package/examples/react-navigation/src/App.js +0 -21
- package/examples/react-navigation/src/DrawerNavigator.js +0 -15
- package/examples/react-navigation/src/DrawerNavigator.test.js +0 -42
- package/examples/react-navigation/src/NativeStackNavigator.js +0 -15
- package/examples/react-navigation/src/NativeStackNavigator.test.js +0 -34
- package/examples/react-navigation/src/StackNavigator.js +0 -15
- package/examples/react-navigation/src/StackNavigator.test.js +0 -34
- package/examples/react-navigation/src/TabNavigator.js +0 -15
- package/examples/react-navigation/src/TabNavigator.test.js +0 -21
- package/examples/react-navigation/src/screens/DetailsScreen.js +0 -43
- package/examples/react-navigation/src/screens/DetailsScreen.test.js +0 -27
- package/examples/react-navigation/src/screens/DrawerHomeScreen.js +0 -26
- package/examples/react-navigation/src/screens/HomeScreen.js +0 -48
- package/examples/react-navigation/src/screens/SettingsScreen.js +0 -20
- package/examples/react-navigation/src/test-utils.js +0 -12
- package/examples/react-navigation/yarn.lock +0 -5018
- package/examples/redux/App.js +0 -27
- package/examples/redux/README.md +0 -5
- package/examples/redux/actions/todoActions.js +0 -25
- package/examples/redux/babel.config.js +0 -6
- package/examples/redux/components/AddTodo.js +0 -73
- package/examples/redux/components/AddTodo.test.js +0 -27
- package/examples/redux/components/TodoElem.js +0 -25
- package/examples/redux/components/TodoList.js +0 -29
- package/examples/redux/components/TodoList.test.js +0 -34
- package/examples/redux/index.js +0 -8
- package/examples/redux/jest-setup.js +0 -2
- package/examples/redux/jest.config.js +0 -4
- package/examples/redux/package.json +0 -23
- package/examples/redux/reducers/index.js +0 -6
- package/examples/redux/reducers/todoReducer.js +0 -27
- package/examples/redux/store.js +0 -10
- package/examples/redux/test-utils.js +0 -11
- package/examples/redux/yarn.lock +0 -4819
- package/experiments-app/.expo/README.md +0 -15
- package/experiments-app/.expo/devices.json +0 -3
- package/experiments-app/.expo/packager-info.json +0 -9
- package/experiments-app/.expo/settings.json +0 -9
- package/experiments-app/.gitignore +0 -17
- package/experiments-app/.prettierrc.js +0 -5
- package/experiments-app/app.json +0 -30
- 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 +0 -6
- package/experiments-app/index.js +0 -4
- package/experiments-app/package.json +0 -29
- package/experiments-app/src/App.tsx +0 -31
- package/experiments-app/src/MainScreen.tsx +0 -52
- package/experiments-app/src/experiments.ts +0 -35
- package/experiments-app/src/screens/FlatListEvents.tsx +0 -57
- package/experiments-app/src/screens/ScrollViewEvents.tsx +0 -65
- package/experiments-app/src/screens/SectionListEvents.tsx +0 -91
- package/experiments-app/src/screens/TextInputEventPropagation.tsx +0 -42
- package/experiments-app/src/screens/TextInputEvents.tsx +0 -48
- package/experiments-app/src/utils/helpers.ts +0 -18
- package/experiments-app/tsconfig.json +0 -6
- package/experiments-app/yarn.lock +0 -6709
- package/experiments-rtl/.babelrc +0 -8
- package/experiments-rtl/.eslintrc.json +0 -3
- package/experiments-rtl/.gitignore +0 -35
- package/experiments-rtl/README.md +0 -34
- package/experiments-rtl/jest-setup.js +0 -1
- package/experiments-rtl/jest.config.js +0 -4
- package/experiments-rtl/next.config.js +0 -4
- package/experiments-rtl/package.json +0 -38
- package/experiments-rtl/postcss.config.js +0 -6
- package/experiments-rtl/public/next.svg +0 -1
- package/experiments-rtl/public/vercel.svg +0 -1
- package/experiments-rtl/src/app/__tests__/click.test.tsx +0 -31
- package/experiments-rtl/src/app/__tests__/managed-text-input.test.tsx +0 -51
- package/experiments-rtl/src/app/globals.css +0 -27
- package/experiments-rtl/src/app/layout.tsx +0 -22
- package/experiments-rtl/src/app/page.tsx +0 -113
- package/experiments-rtl/tailwind.config.ts +0 -20
- package/experiments-rtl/tsconfig.json +0 -28
- package/experiments-rtl/yarn.lock +0 -5418
- package/flow-typed/npm/jest_v26.x.x.js +0 -1218
- package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -81
- package/jest-setup.ts +0 -10
- package/renovate.json +0 -19
- package/scripts/test_react_17 +0 -12
- package/src/__tests__/__snapshots__/render-debug.test.tsx.snap +0 -548
- package/src/__tests__/__snapshots__/render.test.tsx.snap +0 -39
- package/src/__tests__/act.test.tsx +0 -56
- package/src/__tests__/auto-cleanup-skip.test.tsx +0 -39
- package/src/__tests__/auto-cleanup.test.tsx +0 -50
- package/src/__tests__/cleanup.test.tsx +0 -26
- package/src/__tests__/config.test.ts +0 -55
- package/src/__tests__/fireEvent-textInput.test.tsx +0 -154
- package/src/__tests__/fireEvent.test.tsx +0 -485
- package/src/__tests__/host-component-names.test.tsx +0 -109
- package/src/__tests__/host-text-nesting.test.tsx +0 -90
- package/src/__tests__/jest-native.test.tsx +0 -84
- package/src/__tests__/questionsBoard.test.tsx +0 -62
- package/src/__tests__/react-native-api.test.tsx +0 -126
- package/src/__tests__/render-debug.test.tsx +0 -207
- package/src/__tests__/render-stringValidation.test.tsx +0 -157
- package/src/__tests__/render.test.tsx +0 -256
- package/src/__tests__/renderHook.test.tsx +0 -114
- package/src/__tests__/screen.test.tsx +0 -66
- package/src/__tests__/timerUtils.ts +0 -7
- package/src/__tests__/timers.test.ts +0 -27
- package/src/__tests__/waitFor.test.tsx +0 -327
- package/src/__tests__/waitForElementToBeRemoved.test.tsx +0 -151
- package/src/__tests__/within.test.tsx +0 -96
- package/src/act.ts +0 -86
- package/src/cleanup.ts +0 -15
- package/src/config.ts +0 -72
- package/src/fireEvent.ts +0 -159
- package/src/flush-micro-tasks.ts +0 -30
- package/src/helpers/__tests__/accessiblity.test.tsx +0 -373
- package/src/helpers/__tests__/component-tree.test.tsx +0 -226
- package/src/helpers/__tests__/format-default.tsx +0 -114
- package/src/helpers/__tests__/getTextContent.test.tsx +0 -49
- package/src/helpers/__tests__/includeHiddenElements.test.tsx +0 -39
- package/src/helpers/__tests__/query-name.test.ts +0 -10
- package/src/helpers/__tests__/timers.test.ts +0 -8
- package/src/helpers/accessiblity.ts +0 -108
- package/src/helpers/component-tree.ts +0 -94
- package/src/helpers/debugDeep.ts +0 -27
- package/src/helpers/debugShallow.ts +0 -22
- package/src/helpers/deprecation.ts +0 -53
- package/src/helpers/errors.ts +0 -66
- package/src/helpers/findAll.ts +0 -70
- package/src/helpers/format-default.ts +0 -72
- package/src/helpers/format.ts +0 -47
- package/src/helpers/getTextContent.ts +0 -20
- package/src/helpers/host-component-names.tsx +0 -88
- package/src/helpers/matchers/__tests__/matchArrayValue.test.ts +0 -34
- package/src/helpers/matchers/__tests__/matchObject.test.ts +0 -37
- package/src/helpers/matchers/__tests__/matchStringValue.test.ts +0 -15
- package/src/helpers/matchers/accessibilityState.ts +0 -48
- package/src/helpers/matchers/accessibilityValue.ts +0 -24
- package/src/helpers/matchers/matchArrayProp.ts +0 -21
- package/src/helpers/matchers/matchLabelText.ts +0 -50
- package/src/helpers/matchers/matchObjectProp.ts +0 -25
- package/src/helpers/matchers/matchStringProp.ts +0 -23
- package/src/helpers/matchers/matchTextContent.ts +0 -20
- package/src/helpers/pointer-events.ts +0 -27
- package/src/helpers/query-name.ts +0 -4
- package/src/helpers/stringValidation.ts +0 -36
- package/src/helpers/timers.ts +0 -98
- package/src/index.ts +0 -33
- package/src/matches.ts +0 -49
- package/src/pure.ts +0 -27
- package/src/queries/__tests__/a11yState.test.tsx +0 -439
- package/src/queries/__tests__/a11yValue.test.tsx +0 -309
- package/src/queries/__tests__/displayValue.test.tsx +0 -221
- package/src/queries/__tests__/hintText.test.tsx +0 -177
- package/src/queries/__tests__/labelText.test.tsx +0 -242
- package/src/queries/__tests__/makeQueries.test.tsx +0 -235
- package/src/queries/__tests__/placeholderText.test.tsx +0 -136
- package/src/queries/__tests__/role-value.test.tsx +0 -176
- package/src/queries/__tests__/role.test.tsx +0 -824
- package/src/queries/__tests__/testId.test.tsx +0 -200
- package/src/queries/__tests__/text.test.tsx +0 -556
- package/src/queries/a11yState.ts +0 -127
- package/src/queries/a11yValue.ts +0 -127
- package/src/queries/displayValue.ts +0 -71
- package/src/queries/hintText.ts +0 -107
- package/src/queries/labelText.ts +0 -57
- package/src/queries/makeQueries.ts +0 -255
- package/src/queries/options.ts +0 -14
- package/src/queries/placeholderText.ts +0 -72
- package/src/queries/role.ts +0 -131
- package/src/queries/testId.ts +0 -66
- package/src/queries/text.ts +0 -63
- package/src/queries/unsafeProps.ts +0 -76
- package/src/queries/unsafeType.ts +0 -73
- package/src/react-versions.ts +0 -11
- package/src/render-act.ts +0 -19
- package/src/render.tsx +0 -183
- package/src/renderHook.tsx +0 -56
- package/src/screen.ts +0 -123
- package/src/shallow.ts +0 -18
- package/src/test-utils/events.ts +0 -24
- package/src/test-utils/index.ts +0 -1
- package/src/user-event/__tests__/__snapshots__/clear.test.tsx.snap +0 -269
- package/src/user-event/__tests__/clear.test.tsx +0 -217
- package/src/user-event/clear.ts +0 -59
- package/src/user-event/event-builder/common.ts +0 -66
- package/src/user-event/event-builder/index.ts +0 -7
- package/src/user-event/event-builder/text-input.ts +0 -86
- package/src/user-event/index.ts +0 -18
- package/src/user-event/press/__tests__/longPress.real-timers.test.tsx +0 -117
- package/src/user-event/press/__tests__/longPress.test.tsx +0 -157
- package/src/user-event/press/__tests__/press.real-timers.test.tsx +0 -320
- package/src/user-event/press/__tests__/press.test.tsx +0 -457
- package/src/user-event/press/constants.ts +0 -7
- package/src/user-event/press/index.ts +0 -1
- package/src/user-event/press/press.ts +0 -163
- package/src/user-event/setup/index.ts +0 -2
- package/src/user-event/setup/setup.ts +0 -142
- package/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap +0 -339
- package/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap +0 -668
- package/src/user-event/type/__tests__/parseKeys.test.ts +0 -23
- package/src/user-event/type/__tests__/type-managed.test.tsx +0 -120
- package/src/user-event/type/__tests__/type.test.tsx +0 -335
- package/src/user-event/type/index.ts +0 -1
- package/src/user-event/type/parseKeys.ts +0 -41
- package/src/user-event/type/type.ts +0 -138
- package/src/user-event/utils/__tests__/dispatch-event.test.tsx +0 -41
- package/src/user-event/utils/__tests__/wait.test.ts +0 -62
- package/src/user-event/utils/content-size.ts +0 -25
- package/src/user-event/utils/dispatch-event.ts +0 -38
- package/src/user-event/utils/host-components.ts +0 -6
- package/src/user-event/utils/index.ts +0 -6
- package/src/user-event/utils/text-range.ts +0 -4
- package/src/user-event/utils/wait.ts +0 -15
- package/src/user-event/utils/warn-about-real-timers.ts +0 -13
- package/src/waitFor.ts +0 -228
- package/src/waitForElementToBeRemoved.ts +0 -42
- package/src/within.ts +0 -30
- package/tsconfig.json +0 -17
- package/tsconfig.release.json +0 -8
- package/website/.gitignore +0 -20
- package/website/README.md +0 -33
- package/website/docker/.dockerignore +0 -3
- package/website/docker/Dockerfile +0 -9
- package/website/docker/docker-compose.yml +0 -11
- package/website/docs/API.md +0 -940
- package/website/docs/EslintPLluginTestingLibrary.md +0 -28
- package/website/docs/FAQ.md +0 -44
- package/website/docs/GettingStarted.md +0 -100
- package/website/docs/HowShouldIQuery.md +0 -21
- package/website/docs/MigrationV11.md +0 -64
- package/website/docs/MigrationV12.md +0 -67
- package/website/docs/MigrationV2.md +0 -126
- package/website/docs/MigrationV7.md +0 -119
- package/website/docs/MigrationV9.md +0 -67
- package/website/docs/Queries.md +0 -572
- package/website/docs/ReactNavigation.md +0 -371
- package/website/docs/ReduxIntegration.md +0 -137
- package/website/docs/TestingEnvironment.md +0 -154
- package/website/docs/Troubleshooting.md +0 -44
- package/website/docs/UnderstandingAct.md +0 -227
- package/website/docs/UserEvent.md +0 -191
- package/website/docusaurus.config.js +0 -114
- package/website/package.json +0 -31
- package/website/sidebars.js +0 -20
- package/website/src/components/Feature.js +0 -31
- package/website/src/css/custom.css +0 -13
- package/website/src/css/index.module.css +0 -77
- package/website/src/pages/index.js +0 -82
- package/website/static/.nojekyll +0 -0
- package/website/static/css/custom.css +0 -28
- 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 +0 -7669
- package/yarn.lock +0 -7765
- /package/build/helpers/{getTextContent.d.ts → text-content.d.ts} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
3
|
+
import { TextMatch, TextMatchOptions } from '../matches';
|
|
4
|
+
export declare function toHaveDisplayValue(this: jest.MatcherContext, element: ReactTestInstance, expectedValue: TextMatch, options?: TextMatchOptions): {
|
|
5
|
+
pass: boolean;
|
|
6
|
+
message: () => string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toHaveDisplayValue = toHaveDisplayValue;
|
|
7
|
+
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
8
|
+
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
|
+
var _errors = require("../helpers/errors");
|
|
10
|
+
var _textInput = require("../helpers/text-input");
|
|
11
|
+
var _matches = require("../matches");
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
function toHaveDisplayValue(element, expectedValue, options) {
|
|
14
|
+
(0, _utils.checkHostElement)(element, toHaveDisplayValue, this);
|
|
15
|
+
if (!(0, _hostComponentNames.isHostTextInput)(element)) {
|
|
16
|
+
throw new _errors.ErrorWithStack(`toHaveDisplayValue() works only with host "TextInput" elements. Passed element has type "${element.type}".`, toHaveDisplayValue);
|
|
17
|
+
}
|
|
18
|
+
const receivedValue = (0, _textInput.getTextInputValue)(element);
|
|
19
|
+
return {
|
|
20
|
+
pass: (0, _matches.matches)(expectedValue, receivedValue, options?.normalizer, options?.exact),
|
|
21
|
+
message: () => {
|
|
22
|
+
return [(0, _utils.formatMessage)((0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveDisplayValue`, 'element', ''), `Expected element ${this.isNot ? 'not to' : 'to'} have display value`, expectedValue, 'Received', receivedValue)].join('\n');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=to-have-display-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-have-display-value.js","names":["_jestMatcherUtils","require","_hostComponentNames","_errors","_textInput","_matches","_utils","toHaveDisplayValue","element","expectedValue","options","checkHostElement","isHostTextInput","ErrorWithStack","type","receivedValue","getTextInputValue","pass","matches","normalizer","exact","message","formatMessage","matcherHint","isNot","join"],"sources":["../../src/matchers/to-have-display-value.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { getTextInputValue } from '../helpers/text-input';\nimport { TextMatch, TextMatchOptions, matches } from '../matches';\nimport { checkHostElement, formatMessage } from './utils';\n\nexport function toHaveDisplayValue(\n this: jest.MatcherContext,\n element: ReactTestInstance,\n expectedValue: TextMatch,\n options?: TextMatchOptions\n) {\n checkHostElement(element, toHaveDisplayValue, this);\n\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `toHaveDisplayValue() works only with host \"TextInput\" elements. Passed element has type \"${element.type}\".`,\n toHaveDisplayValue\n );\n }\n\n const receivedValue = getTextInputValue(element);\n\n return {\n pass: matches(\n expectedValue,\n receivedValue,\n options?.normalizer,\n options?.exact\n ),\n message: () => {\n return [\n formatMessage(\n matcherHint(\n `${this.isNot ? '.not' : ''}.toHaveDisplayValue`,\n 'element',\n ''\n ),\n `Expected element ${this.isNot ? 'not to' : 'to'} have display value`,\n expectedValue,\n 'Received',\n receivedValue\n ),\n ].join('\\n');\n },\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAEO,SAASM,kBAAkBA,CAEhCC,OAA0B,EAC1BC,aAAwB,EACxBC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACH,OAAO,EAAED,kBAAkB,EAAE,IAAI,CAAC;EAEnD,IAAI,CAAC,IAAAK,mCAAe,EAACJ,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIK,sBAAc,CACrB,4FAA2FL,OAAO,CAACM,IAAK,IAAG,EAC5GP,kBACF,CAAC;EACH;EAEA,MAAMQ,aAAa,GAAG,IAAAC,4BAAiB,EAACR,OAAO,CAAC;EAEhD,OAAO;IACLS,IAAI,EAAE,IAAAC,gBAAO,EACXT,aAAa,EACbM,aAAa,EACbL,OAAO,EAAES,UAAU,EACnBT,OAAO,EAAEU,KACX,CAAC;IACDC,OAAO,EAAEA,CAAA,KAAM;MACb,OAAO,CACL,IAAAC,oBAAa,EACX,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACC,KAAK,GAAG,MAAM,GAAG,EAAG,qBAAoB,EAChD,SAAS,EACT,EACF,CAAC,EACA,oBAAmB,IAAI,CAACA,KAAK,GAAG,QAAQ,GAAG,IAAK,qBAAoB,EACrEf,aAAa,EACb,UAAU,EACVM,aACF,CAAC,CACF,CAACU,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
3
|
+
export declare function toHaveProp(this: jest.MatcherContext, element: ReactTestInstance, name: string, expectedValue: unknown): {
|
|
4
|
+
pass: boolean;
|
|
5
|
+
message: () => string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toHaveProp = toHaveProp;
|
|
7
|
+
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
function toHaveProp(element, name, expectedValue) {
|
|
10
|
+
(0, _utils.checkHostElement)(element, toHaveProp, this);
|
|
11
|
+
const isExpectedValueDefined = expectedValue !== undefined;
|
|
12
|
+
const hasProp = (name in element.props);
|
|
13
|
+
const receivedValue = element.props[name];
|
|
14
|
+
const pass = isExpectedValueDefined ? hasProp && this.equals(expectedValue, receivedValue) : hasProp;
|
|
15
|
+
return {
|
|
16
|
+
pass,
|
|
17
|
+
message: () => {
|
|
18
|
+
const to = this.isNot ? 'not to' : 'to';
|
|
19
|
+
const matcher = (0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveProp`, 'element', (0, _jestMatcherUtils.printExpected)(name), {
|
|
20
|
+
secondArgument: isExpectedValueDefined ? (0, _jestMatcherUtils.printExpected)(expectedValue) : undefined
|
|
21
|
+
});
|
|
22
|
+
return (0, _utils.formatMessage)(matcher, `Expected element ${to} have prop`, formatProp(name, expectedValue), 'Received', hasProp ? formatProp(name, receivedValue) : undefined);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function formatProp(name, value) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === 'string') {
|
|
31
|
+
return `${name}="${value}"`;
|
|
32
|
+
}
|
|
33
|
+
return `${name}={${(0, _jestMatcherUtils.stringify)(value)}}`;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=to-have-prop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-have-prop.js","names":["_jestMatcherUtils","require","_utils","toHaveProp","element","name","expectedValue","checkHostElement","isExpectedValueDefined","undefined","hasProp","props","receivedValue","pass","equals","message","to","isNot","matcher","matcherHint","printExpected","secondArgument","formatMessage","formatProp","value","stringify"],"sources":["../../src/matchers/to-have-prop.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint, stringify, printExpected } from 'jest-matcher-utils';\nimport { checkHostElement, formatMessage } from './utils';\n\nexport function toHaveProp(\n this: jest.MatcherContext,\n element: ReactTestInstance,\n name: string,\n expectedValue: unknown\n) {\n checkHostElement(element, toHaveProp, this);\n\n const isExpectedValueDefined = expectedValue !== undefined;\n const hasProp = name in element.props;\n const receivedValue = element.props[name];\n\n const pass = isExpectedValueDefined\n ? hasProp && this.equals(expectedValue, receivedValue)\n : hasProp;\n\n return {\n pass,\n message: () => {\n const to = this.isNot ? 'not to' : 'to';\n const matcher = matcherHint(\n `${this.isNot ? '.not' : ''}.toHaveProp`,\n 'element',\n printExpected(name),\n {\n secondArgument: isExpectedValueDefined\n ? printExpected(expectedValue)\n : undefined,\n }\n );\n return formatMessage(\n matcher,\n `Expected element ${to} have prop`,\n formatProp(name, expectedValue),\n 'Received',\n hasProp ? formatProp(name, receivedValue) : undefined\n );\n },\n };\n}\n\nfunction formatProp(name: string, value: unknown) {\n if (value === undefined) {\n return name;\n }\n\n if (typeof value === 'string') {\n return `${name}=\"${value}\"`;\n }\n\n return `${name}={${stringify(value)}}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEO,SAASE,UAAUA,CAExBC,OAA0B,EAC1BC,IAAY,EACZC,aAAsB,EACtB;EACA,IAAAC,uBAAgB,EAACH,OAAO,EAAED,UAAU,EAAE,IAAI,CAAC;EAE3C,MAAMK,sBAAsB,GAAGF,aAAa,KAAKG,SAAS;EAC1D,MAAMC,OAAO,IAAGL,IAAI,IAAID,OAAO,CAACO,KAAK;EACrC,MAAMC,aAAa,GAAGR,OAAO,CAACO,KAAK,CAACN,IAAI,CAAC;EAEzC,MAAMQ,IAAI,GAAGL,sBAAsB,GAC/BE,OAAO,IAAI,IAAI,CAACI,MAAM,CAACR,aAAa,EAAEM,aAAa,CAAC,GACpDF,OAAO;EAEX,OAAO;IACLG,IAAI;IACJE,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACC,KAAK,GAAG,QAAQ,GAAG,IAAI;MACvC,MAAMC,OAAO,GAAG,IAAAC,6BAAW,EACxB,GAAE,IAAI,CAACF,KAAK,GAAG,MAAM,GAAG,EAAG,aAAY,EACxC,SAAS,EACT,IAAAG,+BAAa,EAACf,IAAI,CAAC,EACnB;QACEgB,cAAc,EAAEb,sBAAsB,GAClC,IAAAY,+BAAa,EAACd,aAAa,CAAC,GAC5BG;MACN,CACF,CAAC;MACD,OAAO,IAAAa,oBAAa,EAClBJ,OAAO,EACN,oBAAmBF,EAAG,YAAW,EAClCO,UAAU,CAAClB,IAAI,EAAEC,aAAa,CAAC,EAC/B,UAAU,EACVI,OAAO,GAAGa,UAAU,CAAClB,IAAI,EAAEO,aAAa,CAAC,GAAGH,SAC9C,CAAC;IACH;EACF,CAAC;AACH;AAEA,SAASc,UAAUA,CAAClB,IAAY,EAAEmB,KAAc,EAAE;EAChD,IAAIA,KAAK,KAAKf,SAAS,EAAE;IACvB,OAAOJ,IAAI;EACb;EAEA,IAAI,OAAOmB,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAQ,GAAEnB,IAAK,KAAImB,KAAM,GAAE;EAC7B;EAEA,OAAQ,GAAEnB,IAAK,KAAI,IAAAoB,2BAAS,EAACD,KAAK,CAAE,GAAE;AACxC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
3
|
+
import { TextMatch, TextMatchOptions } from '../matches';
|
|
4
|
+
export declare function toHaveTextContent(this: jest.MatcherContext, element: ReactTestInstance, expectedText: TextMatch, options?: TextMatchOptions): {
|
|
5
|
+
pass: boolean;
|
|
6
|
+
message: () => string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toHaveTextContent = toHaveTextContent;
|
|
7
|
+
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
8
|
+
var _textContent = require("../helpers/text-content");
|
|
9
|
+
var _matches = require("../matches");
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
function toHaveTextContent(element, expectedText, options) {
|
|
12
|
+
(0, _utils.checkHostElement)(element, toHaveTextContent, this);
|
|
13
|
+
const text = (0, _textContent.getTextContent)(element);
|
|
14
|
+
return {
|
|
15
|
+
pass: (0, _matches.matches)(expectedText, text, options?.normalizer, options?.exact),
|
|
16
|
+
message: () => {
|
|
17
|
+
return [(0, _utils.formatMessage)((0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveTextContent`, 'element', ''), `Expected element ${this.isNot ? 'not to' : 'to'} have text content`, expectedText, 'Received', text)].join('\n');
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=to-have-text-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-have-text-content.js","names":["_jestMatcherUtils","require","_textContent","_matches","_utils","toHaveTextContent","element","expectedText","options","checkHostElement","text","getTextContent","pass","matches","normalizer","exact","message","formatMessage","matcherHint","isNot","join"],"sources":["../../src/matchers/to-have-text-content.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport { getTextContent } from '../helpers/text-content';\nimport { TextMatch, TextMatchOptions, matches } from '../matches';\nimport { checkHostElement, formatMessage } from './utils';\n\nexport function toHaveTextContent(\n this: jest.MatcherContext,\n element: ReactTestInstance,\n expectedText: TextMatch,\n options?: TextMatchOptions\n) {\n checkHostElement(element, toHaveTextContent, this);\n\n const text = getTextContent(element);\n\n return {\n pass: matches(expectedText, text, options?.normalizer, options?.exact),\n message: () => {\n return [\n formatMessage(\n matcherHint(\n `${this.isNot ? '.not' : ''}.toHaveTextContent`,\n 'element',\n ''\n ),\n `Expected element ${this.isNot ? 'not to' : 'to'} have text content`,\n expectedText,\n 'Received',\n text\n ),\n ].join('\\n');\n },\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,SAASI,iBAAiBA,CAE/BC,OAA0B,EAC1BC,YAAuB,EACvBC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACH,OAAO,EAAED,iBAAiB,EAAE,IAAI,CAAC;EAElD,MAAMK,IAAI,GAAG,IAAAC,2BAAc,EAACL,OAAO,CAAC;EAEpC,OAAO;IACLM,IAAI,EAAE,IAAAC,gBAAO,EAACN,YAAY,EAAEG,IAAI,EAAEF,OAAO,EAAEM,UAAU,EAAEN,OAAO,EAAEO,KAAK,CAAC;IACtEC,OAAO,EAAEA,CAAA,KAAM;MACb,OAAO,CACL,IAAAC,oBAAa,EACX,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACC,KAAK,GAAG,MAAM,GAAG,EAAG,oBAAmB,EAC/C,SAAS,EACT,EACF,CAAC,EACA,oBAAmB,IAAI,CAACA,KAAK,GAAG,QAAQ,GAAG,IAAK,oBAAmB,EACpEZ,YAAY,EACZ,UAAU,EACVG,IACF,CAAC,CACF,CAACU,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { ReactTestInstance } from 'react-test-renderer';
|
|
3
|
+
/**
|
|
4
|
+
* Throws HostElementTypeError if passed element is not a host element.
|
|
5
|
+
*
|
|
6
|
+
* @param element ReactTestInstance to check.
|
|
7
|
+
* @param matcherFn Matcher function calling the check used for formatting error.
|
|
8
|
+
* @param context Jest matcher context used for formatting error.
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkHostElement(element: ReactTestInstance | null | undefined, matcherFn: jest.CustomMatcher, context: jest.MatcherContext): asserts element is ReactTestInstance;
|
|
11
|
+
/***
|
|
12
|
+
* Format given element as a pretty-printed string.
|
|
13
|
+
*
|
|
14
|
+
* @param element Element to format.
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatElement(element: ReactTestInstance | null): string;
|
|
17
|
+
export declare function formatElementArray(elements: ReactTestInstance[]): string;
|
|
18
|
+
export declare function formatMessage(matcher: string, expectedLabel: string, expectedValue: string | RegExp, receivedLabel: string, receivedValue: string | null | undefined): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkHostElement = checkHostElement;
|
|
7
|
+
exports.formatElement = formatElement;
|
|
8
|
+
exports.formatElementArray = formatElementArray;
|
|
9
|
+
exports.formatMessage = formatMessage;
|
|
10
|
+
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
11
|
+
var _prettyFormat = _interopRequireWildcard(require("pretty-format"));
|
|
12
|
+
var _redent = _interopRequireDefault(require("redent"));
|
|
13
|
+
var _componentTree = require("../helpers/component-tree");
|
|
14
|
+
var _formatDefault = require("../helpers/format-default");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
class HostElementTypeError extends Error {
|
|
19
|
+
constructor(received, matcherFn, context) {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
if (Error.captureStackTrace) {
|
|
24
|
+
Error.captureStackTrace(this, matcherFn);
|
|
25
|
+
}
|
|
26
|
+
let withType = '';
|
|
27
|
+
try {
|
|
28
|
+
withType = (0, _jestMatcherUtils.printWithType)('Received', received, _jestMatcherUtils.printReceived);
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// Deliberately empty.
|
|
32
|
+
}
|
|
33
|
+
this.message = [(0, _jestMatcherUtils.matcherHint)(`${context.isNot ? '.not' : ''}.${matcherFn.name}`, 'received', ''), '', `${(0, _jestMatcherUtils.RECEIVED_COLOR)('received')} value must be a host element.`, withType].join('\n');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Throws HostElementTypeError if passed element is not a host element.
|
|
39
|
+
*
|
|
40
|
+
* @param element ReactTestInstance to check.
|
|
41
|
+
* @param matcherFn Matcher function calling the check used for formatting error.
|
|
42
|
+
* @param context Jest matcher context used for formatting error.
|
|
43
|
+
*/
|
|
44
|
+
function checkHostElement(element, matcherFn, context) {
|
|
45
|
+
if (!(0, _componentTree.isHostElement)(element)) {
|
|
46
|
+
throw new HostElementTypeError(element, matcherFn, context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/***
|
|
51
|
+
* Format given element as a pretty-printed string.
|
|
52
|
+
*
|
|
53
|
+
* @param element Element to format.
|
|
54
|
+
*/
|
|
55
|
+
function formatElement(element) {
|
|
56
|
+
if (element == null) {
|
|
57
|
+
return ' null';
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
children,
|
|
61
|
+
...props
|
|
62
|
+
} = element.props;
|
|
63
|
+
const childrenToDisplay = typeof children === 'string' ? [children] : undefined;
|
|
64
|
+
return (0, _redent.default)((0, _prettyFormat.default)({
|
|
65
|
+
// This prop is needed persuade the prettyFormat that the element is
|
|
66
|
+
// a ReactTestRendererJSON instance, so it is formatted as JSX.
|
|
67
|
+
$$typeof: Symbol.for('react.test.json'),
|
|
68
|
+
type: element.type,
|
|
69
|
+
props: (0, _formatDefault.defaultMapProps)(props),
|
|
70
|
+
children: childrenToDisplay
|
|
71
|
+
}, {
|
|
72
|
+
plugins: [_prettyFormat.plugins.ReactTestComponent, _prettyFormat.plugins.ReactElement],
|
|
73
|
+
printFunctionName: false,
|
|
74
|
+
printBasicPrototype: false,
|
|
75
|
+
highlight: true
|
|
76
|
+
}), 2);
|
|
77
|
+
}
|
|
78
|
+
function formatElementArray(elements) {
|
|
79
|
+
if (elements.length === 0) {
|
|
80
|
+
return ' (no elements)';
|
|
81
|
+
}
|
|
82
|
+
return (0, _redent.default)(elements.map(formatElement).join('\n'), 2);
|
|
83
|
+
}
|
|
84
|
+
function formatMessage(matcher, expectedLabel, expectedValue, receivedLabel, receivedValue) {
|
|
85
|
+
return [`${matcher}\n`, `${expectedLabel}:\n${(0, _jestMatcherUtils.EXPECTED_COLOR)((0, _redent.default)(formatValue(expectedValue), 2))}`, `${receivedLabel}:\n${(0, _jestMatcherUtils.RECEIVED_COLOR)((0, _redent.default)(formatValue(receivedValue), 2))}`].join('\n');
|
|
86
|
+
}
|
|
87
|
+
function formatValue(value) {
|
|
88
|
+
return typeof value === 'string' ? value : (0, _jestMatcherUtils.stringify)(value);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_jestMatcherUtils","require","_prettyFormat","_interopRequireWildcard","_redent","_interopRequireDefault","_componentTree","_formatDefault","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","HostElementTypeError","Error","constructor","received","matcherFn","context","captureStackTrace","withType","printWithType","printReceived","e","message","matcherHint","isNot","name","RECEIVED_COLOR","join","checkHostElement","element","isHostElement","formatElement","children","props","childrenToDisplay","undefined","redent","prettyFormat","$$typeof","Symbol","for","type","defaultMapProps","plugins","ReactTestComponent","ReactElement","printFunctionName","printBasicPrototype","highlight","formatElementArray","elements","length","map","formatMessage","matcher","expectedLabel","expectedValue","receivedLabel","receivedValue","EXPECTED_COLOR","formatValue","value","stringify"],"sources":["../../src/matchers/utils.tsx"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n EXPECTED_COLOR,\n RECEIVED_COLOR,\n matcherHint,\n printWithType,\n printReceived,\n stringify,\n} from 'jest-matcher-utils';\nimport prettyFormat, { plugins } from 'pretty-format';\nimport redent from 'redent';\nimport { isHostElement } from '../helpers/component-tree';\nimport { defaultMapProps } from '../helpers/format-default';\n\nclass HostElementTypeError extends Error {\n constructor(\n received: unknown,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n ) {\n super();\n\n /* istanbul ignore next */\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, matcherFn);\n }\n\n let withType = '';\n try {\n withType = printWithType('Received', received, printReceived);\n /* istanbul ignore next */\n } catch (e) {\n // Deliberately empty.\n }\n\n this.message = [\n matcherHint(\n `${context.isNot ? '.not' : ''}.${matcherFn.name}`,\n 'received',\n ''\n ),\n '',\n `${RECEIVED_COLOR('received')} value must be a host element.`,\n withType,\n ].join('\\n');\n }\n}\n\n/**\n * Throws HostElementTypeError if passed element is not a host element.\n *\n * @param element ReactTestInstance to check.\n * @param matcherFn Matcher function calling the check used for formatting error.\n * @param context Jest matcher context used for formatting error.\n */\nexport function checkHostElement(\n element: ReactTestInstance | null | undefined,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n): asserts element is ReactTestInstance {\n if (!isHostElement(element)) {\n throw new HostElementTypeError(element, matcherFn, context);\n }\n}\n\n/***\n * Format given element as a pretty-printed string.\n *\n * @param element Element to format.\n */\nexport function formatElement(element: ReactTestInstance | null) {\n if (element == null) {\n return ' null';\n }\n\n const { children, ...props } = element.props;\n const childrenToDisplay =\n typeof children === 'string' ? [children] : undefined;\n\n return redent(\n prettyFormat(\n {\n // This prop is needed persuade the prettyFormat that the element is\n // a ReactTestRendererJSON instance, so it is formatted as JSX.\n $$typeof: Symbol.for('react.test.json'),\n type: element.type,\n props: defaultMapProps(props),\n children: childrenToDisplay,\n },\n {\n plugins: [plugins.ReactTestComponent, plugins.ReactElement],\n printFunctionName: false,\n printBasicPrototype: false,\n highlight: true,\n }\n ),\n 2\n );\n}\n\nexport function formatElementArray(elements: ReactTestInstance[]) {\n if (elements.length === 0) {\n return ' (no elements)';\n }\n\n return redent(elements.map(formatElement).join('\\n'), 2);\n}\n\nexport function formatMessage(\n matcher: string,\n expectedLabel: string,\n expectedValue: string | RegExp,\n receivedLabel: string,\n receivedValue: string | null | undefined\n) {\n return [\n `${matcher}\\n`,\n `${expectedLabel}:\\n${EXPECTED_COLOR(\n redent(formatValue(expectedValue), 2)\n )}`,\n `${receivedLabel}:\\n${RECEIVED_COLOR(\n redent(formatValue(receivedValue), 2)\n )}`,\n ].join('\\n');\n}\n\nfunction formatValue(value: unknown) {\n return typeof value === 'string' ? value : stringify(value);\n}\n"],"mappings":"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"}
|
package/build/matches.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type TextMatchOptions = {
|
|
|
4
4
|
exact?: boolean;
|
|
5
5
|
normalizer?: NormalizerFn;
|
|
6
6
|
};
|
|
7
|
-
export declare function matches(matcher: TextMatch, text: string, normalizer?: NormalizerFn, exact?: boolean): boolean;
|
|
7
|
+
export declare function matches(matcher: TextMatch, text: string | undefined, normalizer?: NormalizerFn, exact?: boolean): boolean;
|
|
8
8
|
type NormalizerConfig = {
|
|
9
9
|
trim?: boolean;
|
|
10
10
|
collapseWhitespace?: boolean;
|
package/build/matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matches.js","names":["matches","matcher","text","normalizer","getDefaultNormalizer","exact","normalizedText","normalizedMatcher","toLowerCase","includes","lastIndex","test","trim","collapseWhitespace","replace"],"sources":["../src/matches.ts"],"sourcesContent":["export type NormalizerFn = (textToNormalize: string) => string;\n\nexport type TextMatch = string | RegExp;\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nexport function matches(\n matcher: TextMatch,\n text: string,\n normalizer: NormalizerFn = getDefaultNormalizer(),\n exact: boolean = true\n): boolean {\n if (typeof text !== 'string') {\n return false;\n }\n\n const normalizedText = normalizer(text);\n if (typeof matcher === 'string') {\n const normalizedMatcher = normalizer(matcher);\n return exact\n ? normalizedText === normalizedMatcher\n : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase());\n } else {\n // Reset state for global regexes: https://stackoverflow.com/a/1520839/484499\n matcher.lastIndex = 0;\n return matcher.test(normalizedText);\n }\n}\n\ntype NormalizerConfig = {\n trim?: boolean;\n collapseWhitespace?: boolean;\n};\n\nexport function getDefaultNormalizer({\n trim = true,\n collapseWhitespace = true,\n}: NormalizerConfig = {}): NormalizerFn {\n return (text: string) => {\n let normalizedText = text;\n normalizedText = trim ? normalizedText.trim() : normalizedText;\n normalizedText = collapseWhitespace\n ? normalizedText.replace(/\\s+/g, ' ')\n : normalizedText;\n return normalizedText;\n };\n}\n"],"mappings":";;;;;;;AAQO,SAASA,OAAOA,CACrBC,OAAkB,EAClBC,
|
|
1
|
+
{"version":3,"file":"matches.js","names":["matches","matcher","text","normalizer","getDefaultNormalizer","exact","normalizedText","normalizedMatcher","toLowerCase","includes","lastIndex","test","trim","collapseWhitespace","replace"],"sources":["../src/matches.ts"],"sourcesContent":["export type NormalizerFn = (textToNormalize: string) => string;\n\nexport type TextMatch = string | RegExp;\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nexport function matches(\n matcher: TextMatch,\n text: string | undefined,\n normalizer: NormalizerFn = getDefaultNormalizer(),\n exact: boolean = true\n): boolean {\n if (typeof text !== 'string') {\n return false;\n }\n\n const normalizedText = normalizer(text);\n if (typeof matcher === 'string') {\n const normalizedMatcher = normalizer(matcher);\n return exact\n ? normalizedText === normalizedMatcher\n : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase());\n } else {\n // Reset state for global regexes: https://stackoverflow.com/a/1520839/484499\n matcher.lastIndex = 0;\n return matcher.test(normalizedText);\n }\n}\n\ntype NormalizerConfig = {\n trim?: boolean;\n collapseWhitespace?: boolean;\n};\n\nexport function getDefaultNormalizer({\n trim = true,\n collapseWhitespace = true,\n}: NormalizerConfig = {}): NormalizerFn {\n return (text: string) => {\n let normalizedText = text;\n normalizedText = trim ? normalizedText.trim() : normalizedText;\n normalizedText = collapseWhitespace\n ? normalizedText.replace(/\\s+/g, ' ')\n : normalizedText;\n return normalizedText;\n };\n}\n"],"mappings":";;;;;;;AAQO,SAASA,OAAOA,CACrBC,OAAkB,EAClBC,IAAwB,EACxBC,UAAwB,GAAGC,oBAAoB,CAAC,CAAC,EACjDC,KAAc,GAAG,IAAI,EACZ;EACT,IAAI,OAAOH,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAO,KAAK;EACd;EAEA,MAAMI,cAAc,GAAGH,UAAU,CAACD,IAAI,CAAC;EACvC,IAAI,OAAOD,OAAO,KAAK,QAAQ,EAAE;IAC/B,MAAMM,iBAAiB,GAAGJ,UAAU,CAACF,OAAO,CAAC;IAC7C,OAAOI,KAAK,GACRC,cAAc,KAAKC,iBAAiB,GACpCD,cAAc,CAACE,WAAW,CAAC,CAAC,CAACC,QAAQ,CAACF,iBAAiB,CAACC,WAAW,CAAC,CAAC,CAAC;EAC5E,CAAC,MAAM;IACL;IACAP,OAAO,CAACS,SAAS,GAAG,CAAC;IACrB,OAAOT,OAAO,CAACU,IAAI,CAACL,cAAc,CAAC;EACrC;AACF;AAOO,SAASF,oBAAoBA,CAAC;EACnCQ,IAAI,GAAG,IAAI;EACXC,kBAAkB,GAAG;AACL,CAAC,GAAG,CAAC,CAAC,EAAgB;EACtC,OAAQX,IAAY,IAAK;IACvB,IAAII,cAAc,GAAGJ,IAAI;IACzBI,cAAc,GAAGM,IAAI,GAAGN,cAAc,CAACM,IAAI,CAAC,CAAC,GAAGN,cAAc;IAC9DA,cAAc,GAAGO,kBAAkB,GAC/BP,cAAc,CAACQ,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GACnCR,cAAc;IAClB,OAAOA,cAAc;EACvB,CAAC;AACH"}
|
|
@@ -6,15 +6,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.bindByDisplayValueQueries = void 0;
|
|
7
7
|
var _findAll = require("../helpers/findAll");
|
|
8
8
|
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
|
+
var _textInput = require("../helpers/text-input");
|
|
9
10
|
var _matches = require("../matches");
|
|
10
11
|
var _makeQueries = require("./makeQueries");
|
|
11
|
-
const matchDisplayValue = (node,
|
|
12
|
+
const matchDisplayValue = (node, expectedValue, options = {}) => {
|
|
12
13
|
const {
|
|
13
14
|
exact,
|
|
14
15
|
normalizer
|
|
15
16
|
} = options;
|
|
16
|
-
const nodeValue =
|
|
17
|
-
return (0, _matches.matches)(
|
|
17
|
+
const nodeValue = (0, _textInput.getTextInputValue)(node);
|
|
18
|
+
return (0, _matches.matches)(expectedValue, nodeValue, normalizer, exact);
|
|
18
19
|
};
|
|
19
20
|
const queryAllByDisplayValue = instance => function queryAllByDisplayValueFn(displayValue, queryOptions) {
|
|
20
21
|
return (0, _findAll.findAll)(instance, node => (0, _hostComponentNames.isHostTextInput)(node) && matchDisplayValue(node, displayValue, queryOptions), queryOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"displayValue.js","names":["_findAll","require","_hostComponentNames","_matches","_makeQueries","matchDisplayValue","node","
|
|
1
|
+
{"version":3,"file":"displayValue.js","names":["_findAll","require","_hostComponentNames","_textInput","_matches","_makeQueries","matchDisplayValue","node","expectedValue","options","exact","normalizer","nodeValue","getTextInputValue","matches","queryAllByDisplayValue","instance","queryAllByDisplayValueFn","displayValue","queryOptions","findAll","isHostTextInput","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByDisplayValueQueries","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","findByDisplayValue","findAllByDisplayValue","exports"],"sources":["../../src/queries/displayValue.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { findAll } from '../helpers/findAll';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { getTextInputValue } from '../helpers/text-input';\nimport { matches, TextMatch, TextMatchOptions } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByDisplayValueOptions = CommonQueryOptions & TextMatchOptions;\n\nconst matchDisplayValue = (\n node: ReactTestInstance,\n expectedValue: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n const nodeValue = getTextInputValue(node);\n return matches(expectedValue, nodeValue, normalizer, exact);\n};\n\nconst queryAllByDisplayValue = (\n instance: ReactTestInstance\n): QueryAllByQuery<TextMatch, ByDisplayValueOptions> =>\n function queryAllByDisplayValueFn(displayValue, queryOptions) {\n return findAll(\n instance,\n (node) =>\n isHostTextInput(node) &&\n matchDisplayValue(node, displayValue, queryOptions),\n queryOptions\n );\n };\n\nconst getMultipleError = (displayValue: TextMatch) =>\n `Found multiple elements with display value: ${String(displayValue)} `;\nconst getMissingError = (displayValue: TextMatch) =>\n `Unable to find an element with displayValue: ${String(displayValue)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByDisplayValue,\n getMissingError,\n getMultipleError\n);\n\nexport type ByDisplayValueQueries = {\n getByDisplayValue: GetByQuery<TextMatch, ByDisplayValueOptions>;\n getAllByDisplayValue: GetAllByQuery<TextMatch, ByDisplayValueOptions>;\n queryByDisplayValue: QueryByQuery<TextMatch, ByDisplayValueOptions>;\n queryAllByDisplayValue: QueryAllByQuery<TextMatch, ByDisplayValueOptions>;\n findByDisplayValue: FindByQuery<TextMatch, ByDisplayValueOptions>;\n findAllByDisplayValue: FindAllByQuery<TextMatch, ByDisplayValueOptions>;\n};\n\nexport const bindByDisplayValueQueries = (\n instance: ReactTestInstance\n): ByDisplayValueQueries => ({\n getByDisplayValue: getBy(instance),\n getAllByDisplayValue: getAllBy(instance),\n queryByDisplayValue: queryBy(instance),\n queryAllByDisplayValue: queryAllBy(instance),\n findByDisplayValue: findBy(instance),\n findAllByDisplayValue: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAaA,MAAMK,iBAAiB,GAAGA,CACxBC,IAAuB,EACvBC,aAAwB,EACxBC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,MAAMG,SAAS,GAAG,IAAAC,4BAAiB,EAACN,IAAI,CAAC;EACzC,OAAO,IAAAO,gBAAO,EAACN,aAAa,EAAEI,SAAS,EAAED,UAAU,EAAED,KAAK,CAAC;AAC7D,CAAC;AAED,MAAMK,sBAAsB,GAC1BC,QAA2B,IAE3B,SAASC,wBAAwBA,CAACC,YAAY,EAAEC,YAAY,EAAE;EAC5D,OAAO,IAAAC,gBAAO,EACZJ,QAAQ,EACPT,IAAI,IACH,IAAAc,mCAAe,EAACd,IAAI,CAAC,IACrBD,iBAAiB,CAACC,IAAI,EAAEW,YAAY,EAAEC,YAAY,CAAC,EACrDA,YACF,CAAC;AACH,CAAC;AAEH,MAAMG,gBAAgB,GAAIJ,YAAuB,IAC9C,+CAA8CK,MAAM,CAACL,YAAY,CAAE,GAAE;AACxE,MAAMM,eAAe,GAAIN,YAAuB,IAC7C,gDAA+CK,MAAM,CAACL,YAAY,CAAE,EAAC;AAExE,MAAM;EAAEO,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EhB,sBAAsB,EACtBS,eAAe,EACfF,gBACF,CAAC;AAWM,MAAMU,yBAAyB,GACpChB,QAA2B,KACA;EAC3BiB,iBAAiB,EAAER,KAAK,CAACT,QAAQ,CAAC;EAClCkB,oBAAoB,EAAER,QAAQ,CAACV,QAAQ,CAAC;EACxCmB,mBAAmB,EAAER,OAAO,CAACX,QAAQ,CAAC;EACtCD,sBAAsB,EAAEa,UAAU,CAACZ,QAAQ,CAAC;EAC5CoB,kBAAkB,EAAEP,MAAM,CAACb,QAAQ,CAAC;EACpCqB,qBAAqB,EAAEP,SAAS,CAACd,QAAQ;AAC3C,CAAC,CAAC;AAACsB,OAAA,CAAAN,yBAAA,GAAAA,yBAAA"}
|
|
@@ -12,8 +12,8 @@ function queryAllByLabelText(instance) {
|
|
|
12
12
|
return (0, _findAll.findAll)(instance, node => (0, _matchLabelText.matchLabelText)(instance, node, text, queryOptions), queryOptions);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
const getMultipleError = labelText => `Found multiple elements with
|
|
16
|
-
const getMissingError = labelText => `Unable to find an element with
|
|
15
|
+
const getMultipleError = labelText => `Found multiple elements with accessibility label: ${String(labelText)} `;
|
|
16
|
+
const getMissingError = labelText => `Unable to find an element with accessibility label: ${String(labelText)}`;
|
|
17
17
|
const {
|
|
18
18
|
getBy,
|
|
19
19
|
getAllBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labelText.js","names":["_findAll","require","_matchLabelText","_makeQueries","queryAllByLabelText","instance","text","queryOptions","findAll","node","matchLabelText","getMultipleError","labelText","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByLabelTextQueries","getByLabelText","getAllByLabelText","queryByLabelText","findByLabelText","findAllByLabelText","exports"],"sources":["../../src/queries/labelText.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { findAll } from '../helpers/findAll';\nimport { TextMatch, TextMatchOptions } from '../matches';\nimport { matchLabelText } from '../helpers/matchers/matchLabelText';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport { CommonQueryOptions } from './options';\n\ntype ByLabelTextOptions = CommonQueryOptions & TextMatchOptions;\n\nfunction queryAllByLabelText(instance: ReactTestInstance) {\n return (text: TextMatch, queryOptions?: ByLabelTextOptions) => {\n return findAll(\n instance,\n (node) => matchLabelText(instance, node, text, queryOptions),\n queryOptions\n );\n };\n}\n\nconst getMultipleError = (labelText: TextMatch) =>\n `Found multiple elements with
|
|
1
|
+
{"version":3,"file":"labelText.js","names":["_findAll","require","_matchLabelText","_makeQueries","queryAllByLabelText","instance","text","queryOptions","findAll","node","matchLabelText","getMultipleError","labelText","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByLabelTextQueries","getByLabelText","getAllByLabelText","queryByLabelText","findByLabelText","findAllByLabelText","exports"],"sources":["../../src/queries/labelText.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { findAll } from '../helpers/findAll';\nimport { TextMatch, TextMatchOptions } from '../matches';\nimport { matchLabelText } from '../helpers/matchers/matchLabelText';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport { CommonQueryOptions } from './options';\n\ntype ByLabelTextOptions = CommonQueryOptions & TextMatchOptions;\n\nfunction queryAllByLabelText(instance: ReactTestInstance) {\n return (text: TextMatch, queryOptions?: ByLabelTextOptions) => {\n return findAll(\n instance,\n (node) => matchLabelText(instance, node, text, queryOptions),\n queryOptions\n );\n };\n}\n\nconst getMultipleError = (labelText: TextMatch) =>\n `Found multiple elements with accessibility label: ${String(labelText)} `;\nconst getMissingError = (labelText: TextMatch) =>\n `Unable to find an element with accessibility label: ${String(labelText)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByLabelText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByLabelTextQueries = {\n getByLabelText: GetByQuery<TextMatch, ByLabelTextOptions>;\n getAllByLabelText: GetAllByQuery<TextMatch, ByLabelTextOptions>;\n queryByLabelText: QueryByQuery<TextMatch, ByLabelTextOptions>;\n queryAllByLabelText: QueryAllByQuery<TextMatch, ByLabelTextOptions>;\n findByLabelText: FindByQuery<TextMatch, ByLabelTextOptions>;\n findAllByLabelText: FindAllByQuery<TextMatch, ByLabelTextOptions>;\n};\n\nexport const bindByLabelTextQueries = (\n instance: ReactTestInstance\n): ByLabelTextQueries => ({\n getByLabelText: getBy(instance),\n getAllByLabelText: getAllBy(instance),\n queryByLabelText: queryBy(instance),\n queryAllByLabelText: queryAllBy(instance),\n findByLabelText: findBy(instance),\n findAllByLabelText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAaA,SAASG,mBAAmBA,CAACC,QAA2B,EAAE;EACxD,OAAO,CAACC,IAAe,EAAEC,YAAiC,KAAK;IAC7D,OAAO,IAAAC,gBAAO,EACZH,QAAQ,EACPI,IAAI,IAAK,IAAAC,8BAAc,EAACL,QAAQ,EAAEI,IAAI,EAAEH,IAAI,EAAEC,YAAY,CAAC,EAC5DA,YACF,CAAC;EACH,CAAC;AACH;AAEA,MAAMI,gBAAgB,GAAIC,SAAoB,IAC3C,qDAAoDC,MAAM,CAACD,SAAS,CAAE,GAAE;AAC3E,MAAME,eAAe,GAAIF,SAAoB,IAC1C,uDAAsDC,MAAM,CAACD,SAAS,CAAE,EAAC;AAE5E,MAAM;EAAEG,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EjB,mBAAmB,EACnBU,eAAe,EACfH,gBACF,CAAC;AAWM,MAAMW,sBAAsB,GACjCjB,QAA2B,KACH;EACxBkB,cAAc,EAAER,KAAK,CAACV,QAAQ,CAAC;EAC/BmB,iBAAiB,EAAER,QAAQ,CAACX,QAAQ,CAAC;EACrCoB,gBAAgB,EAAER,OAAO,CAACZ,QAAQ,CAAC;EACnCD,mBAAmB,EAAEc,UAAU,CAACb,QAAQ,CAAC;EACzCqB,eAAe,EAAEP,MAAM,CAACd,QAAQ,CAAC;EACjCsB,kBAAkB,EAAEP,SAAS,CAACf,QAAQ;AACxC,CAAC,CAAC;AAACuB,OAAA,CAAAN,sBAAA,GAAAA,sBAAA"}
|
package/build/queries/role.js
CHANGED
|
@@ -28,7 +28,7 @@ const matchAccessibilityValueIfNeeded = (node, value) => {
|
|
|
28
28
|
const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
|
|
29
29
|
return (0, _findAll.findAll)(instance, node =>
|
|
30
30
|
// run the cheapest checks first, and early exit to avoid unneeded computations
|
|
31
|
-
(0, _accessiblity.isAccessibilityElement)(node) && (0, _matchStringProp.matchStringProp)(node
|
|
31
|
+
(0, _accessiblity.isAccessibilityElement)(node) && (0, _matchStringProp.matchStringProp)((0, _accessiblity.getAccessibilityRole)(node), role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibilityValueIfNeeded(node, options?.value) && matchAccessibleNameIfNeeded(node, options?.name), options);
|
|
32
32
|
};
|
|
33
33
|
const formatQueryParams = (role, options = {}) => {
|
|
34
34
|
const params = [`role: "${String(role)}"`];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","names":["_accessiblity","require","_findAll","_accessibilityState","_accessibilityValue","_matchStringProp","_within","_makeQueries","matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","instance","queryAllByRoleFn","role","findAll","isAccessibilityElement","matchStringProp","
|
|
1
|
+
{"version":3,"file":"role.js","names":["_accessiblity","require","_findAll","_accessibilityState","_accessibilityValue","_matchStringProp","_within","_makeQueries","matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","instance","queryAllByRoleFn","role","findAll","isAccessibilityElement","matchStringProp","getAccessibilityRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessiblityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole","exports"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport {\n accessibilityStateKeys,\n accessiblityValueKeys,\n getAccessibilityRole,\n isAccessibilityElement,\n} from '../helpers/accessiblity';\nimport { findAll } from '../helpers/findAll';\nimport {\n AccessibilityStateMatcher,\n matchAccessibilityState,\n} from '../helpers/matchers/accessibilityState';\nimport {\n AccessibilityValueMatcher,\n matchAccessibilityValue,\n} from '../helpers/matchers/accessibilityValue';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport type { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport { CommonQueryOptions } from './options';\n\ntype ByRoleOptions = CommonQueryOptions &\n AccessibilityStateMatcher & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst matchAccessibleStateIfNeeded = (\n node: ReactTestInstance,\n options?: ByRoleOptions\n) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (\n node: ReactTestInstance,\n value?: AccessibilityValueMatcher\n) => {\n return value != null ? matchAccessibilityValue(node, value) : true;\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): QueryAllByQuery<TextMatch, ByRoleOptions> =>\n function queryAllByRoleFn(role, options) {\n return findAll(\n instance,\n (node) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n isAccessibilityElement(node) &&\n matchStringProp(getAccessibilityRole(node), role) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibilityValueIfNeeded(node, options?.value) &&\n matchAccessibleNameIfNeeded(node, options?.name),\n options\n );\n };\n\nconst formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {\n const params = [`role: \"${String(role)}\"`];\n\n if (options.name) {\n params.push(`name: \"${String(options.name)}\"`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n params.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n accessiblityValueKeys.forEach((valueKey) => {\n if (options?.value?.[valueKey] !== undefined) {\n params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);\n }\n });\n\n return params.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${formatQueryParams(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${formatQueryParams(role, options)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":"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"}
|
package/build/render.d.ts
CHANGED
|
@@ -61,45 +61,27 @@ export default function render<T>(component: React.ReactElement<T>, options?: Re
|
|
|
61
61
|
findAllByAccessibilityState: import("./queries/makeQueries").FindAllByQuery<import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher, import("./queries/options").CommonQueryOptions>;
|
|
62
62
|
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
63
63
|
name?: import("./matches").TextMatch | undefined;
|
|
64
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
65
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
66
|
-
* to assert on the output.
|
|
67
|
-
*/
|
|
64
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
68
65
|
}>;
|
|
69
66
|
getAllByRole: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
70
67
|
name?: import("./matches").TextMatch | undefined;
|
|
71
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
72
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
73
|
-
* to assert on the output.
|
|
74
|
-
*/
|
|
68
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
75
69
|
}>;
|
|
76
70
|
queryByRole: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
77
71
|
name?: import("./matches").TextMatch | undefined;
|
|
78
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
79
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
80
|
-
* to assert on the output.
|
|
81
|
-
*/
|
|
72
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
82
73
|
}>;
|
|
83
74
|
queryAllByRole: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
84
75
|
name?: import("./matches").TextMatch | undefined;
|
|
85
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
86
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
87
|
-
* to assert on the output.
|
|
88
|
-
*/
|
|
76
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
89
77
|
}>;
|
|
90
78
|
findByRole: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
91
79
|
name?: import("./matches").TextMatch | undefined;
|
|
92
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
93
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
94
|
-
* to assert on the output.
|
|
95
|
-
*/
|
|
80
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
96
81
|
}>;
|
|
97
82
|
findAllByRole: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
98
83
|
name?: import("./matches").TextMatch | undefined;
|
|
99
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
100
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
101
|
-
* to assert on the output.
|
|
102
|
-
*/
|
|
84
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
103
85
|
}>;
|
|
104
86
|
getByHintText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
105
87
|
getAllByHintText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
@@ -203,45 +185,27 @@ export declare function renderInternal<T>(component: React.ReactElement<T>, { wr
|
|
|
203
185
|
findAllByAccessibilityState: import("./queries/makeQueries").FindAllByQuery<import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher, import("./queries/options").CommonQueryOptions>;
|
|
204
186
|
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
205
187
|
name?: import("./matches").TextMatch | undefined;
|
|
206
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
207
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
208
|
-
* to assert on the output.
|
|
209
|
-
*/
|
|
188
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
210
189
|
}>;
|
|
211
190
|
getAllByRole: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
212
191
|
name?: import("./matches").TextMatch | undefined;
|
|
213
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
214
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
215
|
-
* to assert on the output.
|
|
216
|
-
*/
|
|
192
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
217
193
|
}>;
|
|
218
194
|
queryByRole: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
219
195
|
name?: import("./matches").TextMatch | undefined;
|
|
220
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
221
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
222
|
-
* to assert on the output.
|
|
223
|
-
*/
|
|
196
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
224
197
|
}>;
|
|
225
198
|
queryAllByRole: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
226
199
|
name?: import("./matches").TextMatch | undefined;
|
|
227
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
228
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
229
|
-
* to assert on the output.
|
|
230
|
-
*/
|
|
200
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
231
201
|
}>;
|
|
232
202
|
findByRole: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
233
203
|
name?: import("./matches").TextMatch | undefined;
|
|
234
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
235
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
236
|
-
* to assert on the output.
|
|
237
|
-
*/
|
|
204
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
238
205
|
}>;
|
|
239
206
|
findAllByRole: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./helpers/matchers/accessibilityState").AccessibilityStateMatcher & {
|
|
240
207
|
name?: import("./matches").TextMatch | undefined;
|
|
241
|
-
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
242
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
243
|
-
* to assert on the output.
|
|
244
|
-
*/
|
|
208
|
+
value?: import("./helpers/matchers/accessibilityValue").AccessibilityValueMatcher | undefined;
|
|
245
209
|
}>;
|
|
246
210
|
getByHintText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
247
211
|
getAllByHintText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.clear = clear;
|
|
7
7
|
var _errors = require("../helpers/errors");
|
|
8
8
|
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
|
+
var _textInput = require("../helpers/text-input");
|
|
9
10
|
var _pointerEvents = require("../helpers/pointer-events");
|
|
10
11
|
var _eventBuilder = require("./event-builder");
|
|
11
12
|
var _utils = require("./utils");
|
|
@@ -14,7 +15,7 @@ async function clear(element) {
|
|
|
14
15
|
if (!(0, _hostComponentNames.isHostTextInput)(element)) {
|
|
15
16
|
throw new _errors.ErrorWithStack(`clear() only supports host "TextInput" elements. Passed element has type: "${element.type}".`, clear);
|
|
16
17
|
}
|
|
17
|
-
if (!(0,
|
|
18
|
+
if (!(0, _textInput.isTextInputEditable)(element) || !(0, _pointerEvents.isPointerEventEnabled)(element)) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_eventBuilder","_utils","_type","clear","element","isHostTextInput","ErrorWithStack","type","
|
|
1
|
+
{"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_textInput","_pointerEvents","_eventBuilder","_utils","_type","clear","element","isHostTextInput","ErrorWithStack","type","isTextInputEditable","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","previousText","props","value","defaultValue","selectionRange","start","end","length","TextInput","selectionChange","finalText","emitTypingEvents","config","wait","endEditing","blur"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isTextInputEditable } from '../helpers/text-input';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { EventBuilder } from './event-builder';\nimport { UserEventInstance } from './setup';\nimport { dispatchEvent, wait } from './utils';\nimport { emitTypingEvents } from './type/type';\n\nexport async function clear(\n this: UserEventInstance,\n element: ReactTestInstance\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `clear() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n clear\n );\n }\n\n if (!isTextInputEditable(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const previousText = element.props.value ?? element.props.defaultValue ?? '';\n const selectionRange = {\n start: 0,\n end: previousText.length,\n };\n dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(selectionRange)\n );\n\n // 3. Press backspace\n const finalText = '';\n await emitTypingEvents(\n this.config,\n element,\n 'Backspace',\n finalText,\n previousText\n );\n\n // 4. Exit element\n await wait(this.config);\n dispatchEvent(\n element,\n 'endEditing',\n EventBuilder.TextInput.endEditing(finalText)\n );\n\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAEzBC,OAA0B,EACX;EACf,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CACrB,8EAA6EF,OAAO,CAACG,IAAK,IAAG,EAC9FJ,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAK,8BAAmB,EAACJ,OAAO,CAAC,IAAI,CAAC,IAAAK,oCAAqB,EAACL,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,IAAAM,oBAAa,EAACN,OAAO,EAAE,OAAO,EAAEO,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAE5D;EACA,MAAMC,YAAY,GAAGV,OAAO,CAACW,KAAK,CAACC,KAAK,IAAIZ,OAAO,CAACW,KAAK,CAACE,YAAY,IAAI,EAAE;EAC5E,MAAMC,cAAc,GAAG;IACrBC,KAAK,EAAE,CAAC;IACRC,GAAG,EAAEN,YAAY,CAACO;EACpB,CAAC;EACD,IAAAX,oBAAa,EACXN,OAAO,EACP,iBAAiB,EACjBO,0BAAY,CAACW,SAAS,CAACC,eAAe,CAACL,cAAc,CACvD,CAAC;;EAED;EACA,MAAMM,SAAS,GAAG,EAAE;EACpB,MAAM,IAAAC,sBAAgB,EACpB,IAAI,CAACC,MAAM,EACXtB,OAAO,EACP,WAAW,EACXoB,SAAS,EACTV,YACF,CAAC;;EAED;EACA,MAAM,IAAAa,WAAI,EAAC,IAAI,CAACD,MAAM,CAAC;EACvB,IAAAhB,oBAAa,EACXN,OAAO,EACP,YAAY,EACZO,0BAAY,CAACW,SAAS,CAACM,UAAU,CAACJ,SAAS,CAC7C,CAAC;EAED,IAAAd,oBAAa,EAACN,OAAO,EAAE,MAAM,EAAEO,0BAAY,CAACC,MAAM,CAACiB,IAAI,CAAC,CAAC,CAAC;AAC5D"}
|
|
@@ -7,6 +7,7 @@ exports.longPress = longPress;
|
|
|
7
7
|
exports.press = press;
|
|
8
8
|
var _act = _interopRequireDefault(require("../../act"));
|
|
9
9
|
var _componentTree = require("../../helpers/component-tree");
|
|
10
|
+
var _textInput = require("../../helpers/text-input");
|
|
10
11
|
var _pointerEvents = require("../../helpers/pointer-events");
|
|
11
12
|
var _hostComponentNames = require("../../helpers/host-component-names");
|
|
12
13
|
var _eventBuilder = require("../event-builder");
|
|
@@ -30,7 +31,7 @@ const basePress = async (config, element, options) => {
|
|
|
30
31
|
await emitTextPressEvents(config, element, options);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
if ((0,
|
|
34
|
+
if ((0, _hostComponentNames.isHostTextInput)(element) && (0, _textInput.isTextInputEditable)(element) && (0, _pointerEvents.isPointerEventEnabled)(element)) {
|
|
34
35
|
await emitTextInputPressEvents(config, element, options);
|
|
35
36
|
return;
|
|
36
37
|
}
|