@testing-library/react-native 12.2.1 → 12.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- 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/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/src/queries/role.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import {
|
|
3
|
-
accessibilityStateKeys,
|
|
4
|
-
accessiblityValueKeys,
|
|
5
|
-
isAccessibilityElement,
|
|
6
|
-
} from '../helpers/accessiblity';
|
|
7
|
-
import { findAll } from '../helpers/findAll';
|
|
8
|
-
import {
|
|
9
|
-
AccessibilityStateMatcher,
|
|
10
|
-
matchAccessibilityState,
|
|
11
|
-
} from '../helpers/matchers/accessibilityState';
|
|
12
|
-
import {
|
|
13
|
-
AccessibilityValueMatcher,
|
|
14
|
-
matchAccessibilityValue,
|
|
15
|
-
} from '../helpers/matchers/accessibilityValue';
|
|
16
|
-
import { matchStringProp } from '../helpers/matchers/matchStringProp';
|
|
17
|
-
import type { TextMatch } from '../matches';
|
|
18
|
-
import { getQueriesForElement } from '../within';
|
|
19
|
-
import { makeQueries } from './makeQueries';
|
|
20
|
-
import type {
|
|
21
|
-
FindAllByQuery,
|
|
22
|
-
FindByQuery,
|
|
23
|
-
GetAllByQuery,
|
|
24
|
-
GetByQuery,
|
|
25
|
-
QueryAllByQuery,
|
|
26
|
-
QueryByQuery,
|
|
27
|
-
} from './makeQueries';
|
|
28
|
-
import { CommonQueryOptions } from './options';
|
|
29
|
-
|
|
30
|
-
type ByRoleOptions = CommonQueryOptions &
|
|
31
|
-
AccessibilityStateMatcher & {
|
|
32
|
-
name?: TextMatch;
|
|
33
|
-
value?: AccessibilityValueMatcher;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const matchAccessibleNameIfNeeded = (
|
|
37
|
-
node: ReactTestInstance,
|
|
38
|
-
name?: TextMatch
|
|
39
|
-
) => {
|
|
40
|
-
if (name == null) return true;
|
|
41
|
-
|
|
42
|
-
const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);
|
|
43
|
-
return (
|
|
44
|
-
queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const matchAccessibleStateIfNeeded = (
|
|
49
|
-
node: ReactTestInstance,
|
|
50
|
-
options?: ByRoleOptions
|
|
51
|
-
) => {
|
|
52
|
-
return options != null ? matchAccessibilityState(node, options) : true;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const matchAccessibilityValueIfNeeded = (
|
|
56
|
-
node: ReactTestInstance,
|
|
57
|
-
value?: AccessibilityValueMatcher
|
|
58
|
-
) => {
|
|
59
|
-
return value != null ? matchAccessibilityValue(node, value) : true;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const queryAllByRole = (
|
|
63
|
-
instance: ReactTestInstance
|
|
64
|
-
): QueryAllByQuery<TextMatch, ByRoleOptions> =>
|
|
65
|
-
function queryAllByRoleFn(role, options) {
|
|
66
|
-
return findAll(
|
|
67
|
-
instance,
|
|
68
|
-
(node) =>
|
|
69
|
-
// run the cheapest checks first, and early exit to avoid unneeded computations
|
|
70
|
-
isAccessibilityElement(node) &&
|
|
71
|
-
matchStringProp(node.props.accessibilityRole, role) &&
|
|
72
|
-
matchAccessibleStateIfNeeded(node, options) &&
|
|
73
|
-
matchAccessibilityValueIfNeeded(node, options?.value) &&
|
|
74
|
-
matchAccessibleNameIfNeeded(node, options?.name),
|
|
75
|
-
options
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {
|
|
80
|
-
const params = [`role: "${String(role)}"`];
|
|
81
|
-
|
|
82
|
-
if (options.name) {
|
|
83
|
-
params.push(`name: "${String(options.name)}"`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
accessibilityStateKeys.forEach((stateKey) => {
|
|
87
|
-
if (options[stateKey] !== undefined) {
|
|
88
|
-
params.push(`${stateKey} state: ${options[stateKey]}`);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
accessiblityValueKeys.forEach((valueKey) => {
|
|
93
|
-
if (options?.value?.[valueKey] !== undefined) {
|
|
94
|
-
params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return params.join(', ');
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>
|
|
102
|
-
`Found multiple elements with ${formatQueryParams(role, options)}`;
|
|
103
|
-
|
|
104
|
-
const getMissingError = (role: TextMatch, options?: ByRoleOptions) =>
|
|
105
|
-
`Unable to find an element with ${formatQueryParams(role, options)}`;
|
|
106
|
-
|
|
107
|
-
const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
|
|
108
|
-
queryAllByRole,
|
|
109
|
-
getMissingError,
|
|
110
|
-
getMultipleError
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
export type ByRoleQueries = {
|
|
114
|
-
getByRole: GetByQuery<TextMatch, ByRoleOptions>;
|
|
115
|
-
getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;
|
|
116
|
-
queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;
|
|
117
|
-
queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;
|
|
118
|
-
findByRole: FindByQuery<TextMatch, ByRoleOptions>;
|
|
119
|
-
findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const bindByRoleQueries = (
|
|
123
|
-
instance: ReactTestInstance
|
|
124
|
-
): ByRoleQueries => ({
|
|
125
|
-
getByRole: getBy(instance),
|
|
126
|
-
getAllByRole: getAllBy(instance),
|
|
127
|
-
queryByRole: queryBy(instance),
|
|
128
|
-
queryAllByRole: queryAllBy(instance),
|
|
129
|
-
findByRole: findBy(instance),
|
|
130
|
-
findAllByRole: findAllBy(instance),
|
|
131
|
-
});
|
package/src/queries/testId.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { findAll } from '../helpers/findAll';
|
|
3
|
-
import { matches, TextMatch, TextMatchOptions } from '../matches';
|
|
4
|
-
import { makeQueries } from './makeQueries';
|
|
5
|
-
import type {
|
|
6
|
-
FindAllByQuery,
|
|
7
|
-
FindByQuery,
|
|
8
|
-
GetAllByQuery,
|
|
9
|
-
GetByQuery,
|
|
10
|
-
QueryAllByQuery,
|
|
11
|
-
QueryByQuery,
|
|
12
|
-
} from './makeQueries';
|
|
13
|
-
import type { CommonQueryOptions } from './options';
|
|
14
|
-
|
|
15
|
-
type ByTestIdOptions = CommonQueryOptions & TextMatchOptions;
|
|
16
|
-
|
|
17
|
-
const matchTestId = (
|
|
18
|
-
node: ReactTestInstance,
|
|
19
|
-
testId: TextMatch,
|
|
20
|
-
options: TextMatchOptions = {}
|
|
21
|
-
) => {
|
|
22
|
-
const { exact, normalizer } = options;
|
|
23
|
-
return matches(testId, node.props.testID, normalizer, exact);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const queryAllByTestId = (
|
|
27
|
-
instance: ReactTestInstance
|
|
28
|
-
): QueryAllByQuery<TextMatch, ByTestIdOptions> =>
|
|
29
|
-
function queryAllByTestIdFn(testId, queryOptions) {
|
|
30
|
-
return findAll(
|
|
31
|
-
instance,
|
|
32
|
-
(node) => matchTestId(node, testId, queryOptions),
|
|
33
|
-
queryOptions
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const getMultipleError = (testId: TextMatch) =>
|
|
38
|
-
`Found multiple elements with testID: ${String(testId)}`;
|
|
39
|
-
const getMissingError = (testId: TextMatch) =>
|
|
40
|
-
`Unable to find an element with testID: ${String(testId)}`;
|
|
41
|
-
|
|
42
|
-
const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
|
|
43
|
-
queryAllByTestId,
|
|
44
|
-
getMissingError,
|
|
45
|
-
getMultipleError
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
export type ByTestIdQueries = {
|
|
49
|
-
getByTestId: GetByQuery<TextMatch, ByTestIdOptions>;
|
|
50
|
-
getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;
|
|
51
|
-
queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;
|
|
52
|
-
queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;
|
|
53
|
-
findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;
|
|
54
|
-
findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const bindByTestIdQueries = (
|
|
58
|
-
instance: ReactTestInstance
|
|
59
|
-
): ByTestIdQueries => ({
|
|
60
|
-
getByTestId: getBy(instance),
|
|
61
|
-
getAllByTestId: getAllBy(instance),
|
|
62
|
-
queryByTestId: queryBy(instance),
|
|
63
|
-
queryAllByTestId: queryAllBy(instance),
|
|
64
|
-
findByTestId: findBy(instance),
|
|
65
|
-
findAllByTestId: findAllBy(instance),
|
|
66
|
-
});
|
package/src/queries/text.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { findAll } from '../helpers/findAll';
|
|
3
|
-
import { isHostText } from '../helpers/host-component-names';
|
|
4
|
-
import { matchTextContent } from '../helpers/matchers/matchTextContent';
|
|
5
|
-
import { TextMatch, TextMatchOptions } from '../matches';
|
|
6
|
-
import { makeQueries } from './makeQueries';
|
|
7
|
-
import type {
|
|
8
|
-
FindAllByQuery,
|
|
9
|
-
FindByQuery,
|
|
10
|
-
GetAllByQuery,
|
|
11
|
-
GetByQuery,
|
|
12
|
-
QueryAllByQuery,
|
|
13
|
-
QueryByQuery,
|
|
14
|
-
} from './makeQueries';
|
|
15
|
-
import type { CommonQueryOptions } from './options';
|
|
16
|
-
|
|
17
|
-
type ByTextOptions = CommonQueryOptions & TextMatchOptions;
|
|
18
|
-
|
|
19
|
-
const queryAllByText = (
|
|
20
|
-
instance: ReactTestInstance
|
|
21
|
-
): QueryAllByQuery<TextMatch, ByTextOptions> =>
|
|
22
|
-
function queryAllByTextFn(text, options = {}) {
|
|
23
|
-
return findAll(
|
|
24
|
-
instance,
|
|
25
|
-
(node) => isHostText(node) && matchTextContent(node, text, options),
|
|
26
|
-
{
|
|
27
|
-
...options,
|
|
28
|
-
matchDeepestOnly: true,
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const getMultipleError = (text: TextMatch) =>
|
|
34
|
-
`Found multiple elements with text: ${String(text)}`;
|
|
35
|
-
|
|
36
|
-
const getMissingError = (text: TextMatch) =>
|
|
37
|
-
`Unable to find an element with text: ${String(text)}`;
|
|
38
|
-
|
|
39
|
-
const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
|
|
40
|
-
queryAllByText,
|
|
41
|
-
getMissingError,
|
|
42
|
-
getMultipleError
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
export type ByTextQueries = {
|
|
46
|
-
getByText: GetByQuery<TextMatch, ByTextOptions>;
|
|
47
|
-
getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;
|
|
48
|
-
queryByText: QueryByQuery<TextMatch, ByTextOptions>;
|
|
49
|
-
queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;
|
|
50
|
-
findByText: FindByQuery<TextMatch, ByTextOptions>;
|
|
51
|
-
findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const bindByTextQueries = (
|
|
55
|
-
instance: ReactTestInstance
|
|
56
|
-
): ByTextQueries => ({
|
|
57
|
-
getByText: getBy(instance),
|
|
58
|
-
getAllByText: getAllBy(instance),
|
|
59
|
-
queryByText: queryBy(instance),
|
|
60
|
-
queryAllByText: queryAllBy(instance),
|
|
61
|
-
findByText: findBy(instance),
|
|
62
|
-
findAllByText: findAllBy(instance),
|
|
63
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import prettyFormat from 'pretty-format';
|
|
3
|
-
import { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';
|
|
4
|
-
import { createQueryByError } from '../helpers/errors';
|
|
5
|
-
|
|
6
|
-
const UNSAFE_getByProps = (
|
|
7
|
-
instance: ReactTestInstance
|
|
8
|
-
): ((props: { [propName: string]: any }) => ReactTestInstance) =>
|
|
9
|
-
function getByPropsFn(props: { [propName: string]: any }) {
|
|
10
|
-
try {
|
|
11
|
-
return instance.findByProps(props);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const UNSAFE_getAllByProps = (
|
|
18
|
-
instance: ReactTestInstance
|
|
19
|
-
): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>
|
|
20
|
-
function getAllByPropsFn(props: { [propName: string]: any }) {
|
|
21
|
-
const results = instance.findAllByProps(props);
|
|
22
|
-
if (results.length === 0) {
|
|
23
|
-
throw new ErrorWithStack(
|
|
24
|
-
`No instances found with props:\n${prettyFormat(props)}`,
|
|
25
|
-
getAllByPropsFn
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return results;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const UNSAFE_queryByProps = (
|
|
32
|
-
instance: ReactTestInstance
|
|
33
|
-
): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>
|
|
34
|
-
function queryByPropsFn(props: { [propName: string]: any }) {
|
|
35
|
-
try {
|
|
36
|
-
return UNSAFE_getByProps(instance)(props);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return createQueryByError(error, queryByPropsFn);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const UNSAFE_queryAllByProps =
|
|
43
|
-
(
|
|
44
|
-
instance: ReactTestInstance
|
|
45
|
-
): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>
|
|
46
|
-
(props: { [propName: string]: any }) => {
|
|
47
|
-
try {
|
|
48
|
-
return UNSAFE_getAllByProps(instance)(props);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Unsafe aliases
|
|
55
|
-
export type UnsafeByPropsQueries = {
|
|
56
|
-
UNSAFE_getByProps: (props: { [key: string]: any }) => ReactTestInstance;
|
|
57
|
-
UNSAFE_getAllByProps: (props: {
|
|
58
|
-
[key: string]: any;
|
|
59
|
-
}) => Array<ReactTestInstance>;
|
|
60
|
-
UNSAFE_queryByProps: (props: {
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
}) => ReactTestInstance | null;
|
|
63
|
-
UNSAFE_queryAllByProps: (props: {
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
}) => Array<ReactTestInstance>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// TODO: migrate to makeQueries pattern
|
|
69
|
-
export const bindUnsafeByPropsQueries = (
|
|
70
|
-
instance: ReactTestInstance
|
|
71
|
-
): UnsafeByPropsQueries => ({
|
|
72
|
-
UNSAFE_getByProps: UNSAFE_getByProps(instance),
|
|
73
|
-
UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
|
|
74
|
-
UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
|
|
75
|
-
UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),
|
|
76
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';
|
|
4
|
-
import { createQueryByError } from '../helpers/errors';
|
|
5
|
-
|
|
6
|
-
const UNSAFE_getByType = (
|
|
7
|
-
instance: ReactTestInstance
|
|
8
|
-
): ((type: React.ComponentType<any>) => ReactTestInstance) =>
|
|
9
|
-
function getByTypeFn(type: React.ComponentType<any>) {
|
|
10
|
-
try {
|
|
11
|
-
return instance.findByType(type);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const UNSAFE_getAllByType = (
|
|
18
|
-
instance: ReactTestInstance
|
|
19
|
-
): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>
|
|
20
|
-
function getAllByTypeFn(type: React.ComponentType<any>) {
|
|
21
|
-
const results = instance.findAllByType(type);
|
|
22
|
-
if (results.length === 0) {
|
|
23
|
-
throw new ErrorWithStack('No instances found', getAllByTypeFn);
|
|
24
|
-
}
|
|
25
|
-
return results;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const UNSAFE_queryByType = (
|
|
29
|
-
instance: ReactTestInstance
|
|
30
|
-
): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>
|
|
31
|
-
function queryByTypeFn(type: React.ComponentType<any>) {
|
|
32
|
-
try {
|
|
33
|
-
return UNSAFE_getByType(instance)(type);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
return createQueryByError(error, queryByTypeFn);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const UNSAFE_queryAllByType =
|
|
40
|
-
(
|
|
41
|
-
instance: ReactTestInstance
|
|
42
|
-
): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>
|
|
43
|
-
(type: React.ComponentType<any>) => {
|
|
44
|
-
try {
|
|
45
|
-
return UNSAFE_getAllByType(instance)(type);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Unsafe aliases
|
|
52
|
-
export type UnsafeByTypeQueries = {
|
|
53
|
-
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
|
|
54
|
-
UNSAFE_getAllByType: <P>(
|
|
55
|
-
type: React.ComponentType<P>
|
|
56
|
-
) => Array<ReactTestInstance>;
|
|
57
|
-
UNSAFE_queryByType: <P>(
|
|
58
|
-
type: React.ComponentType<P>
|
|
59
|
-
) => ReactTestInstance | null;
|
|
60
|
-
UNSAFE_queryAllByType: <P>(
|
|
61
|
-
type: React.ComponentType<P>
|
|
62
|
-
) => Array<ReactTestInstance>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// TODO: migrate to makeQueries pattern
|
|
66
|
-
export const bindUnsafeByTypeQueries = (
|
|
67
|
-
instance: ReactTestInstance
|
|
68
|
-
): UnsafeByTypeQueries => ({
|
|
69
|
-
UNSAFE_getByType: UNSAFE_getByType(instance),
|
|
70
|
-
UNSAFE_getAllByType: UNSAFE_getAllByType(instance),
|
|
71
|
-
UNSAFE_queryByType: UNSAFE_queryByType(instance),
|
|
72
|
-
UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),
|
|
73
|
-
});
|
package/src/react-versions.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export function checkReactVersionAtLeast(
|
|
4
|
-
major: number,
|
|
5
|
-
minor: number
|
|
6
|
-
): boolean {
|
|
7
|
-
if (React.version === undefined) return false;
|
|
8
|
-
const [actualMajor, actualMinor] = React.version.split('.').map(Number);
|
|
9
|
-
|
|
10
|
-
return actualMajor > major || (actualMajor === major && actualMinor >= minor);
|
|
11
|
-
}
|
package/src/render-act.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import TestRenderer from 'react-test-renderer';
|
|
2
|
-
import type {
|
|
3
|
-
ReactTestRenderer,
|
|
4
|
-
TestRendererOptions,
|
|
5
|
-
} from 'react-test-renderer';
|
|
6
|
-
|
|
7
|
-
export function renderWithAct(
|
|
8
|
-
component: React.ReactElement,
|
|
9
|
-
options?: TestRendererOptions
|
|
10
|
-
): ReactTestRenderer {
|
|
11
|
-
let renderer: ReactTestRenderer;
|
|
12
|
-
|
|
13
|
-
TestRenderer.act(() => {
|
|
14
|
-
renderer = TestRenderer.create(component, options);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// @ts-ignore act is synchronous, so renderer is already initialised here
|
|
18
|
-
return renderer;
|
|
19
|
-
}
|
package/src/render.tsx
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { Profiler } from 'react';
|
|
4
|
-
import act from './act';
|
|
5
|
-
import { addToCleanupQueue } from './cleanup';
|
|
6
|
-
import { getConfig } from './config';
|
|
7
|
-
import { getHostChildren } from './helpers/component-tree';
|
|
8
|
-
import debugDeep, { DebugOptions } from './helpers/debugDeep';
|
|
9
|
-
import debugShallow from './helpers/debugShallow';
|
|
10
|
-
import { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';
|
|
11
|
-
import { validateStringsRenderedWithinText } from './helpers/stringValidation';
|
|
12
|
-
import { renderWithAct } from './render-act';
|
|
13
|
-
import { setRenderResult, screen } from './screen';
|
|
14
|
-
import { getQueriesForElement } from './within';
|
|
15
|
-
|
|
16
|
-
export interface RenderOptions {
|
|
17
|
-
wrapper?: React.ComponentType<any>;
|
|
18
|
-
createNodeMock?: (element: React.ReactElement) => any;
|
|
19
|
-
unstable_validateStringsRenderedWithinText?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type RenderResult = ReturnType<typeof render>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
26
|
-
* to assert on the output.
|
|
27
|
-
*/
|
|
28
|
-
export default function render<T>(
|
|
29
|
-
component: React.ReactElement<T>,
|
|
30
|
-
options: RenderOptions = {}
|
|
31
|
-
) {
|
|
32
|
-
return renderInternal(component, options);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface RenderInternalOptions extends RenderOptions {
|
|
36
|
-
detectHostComponentNames?: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function renderInternal<T>(
|
|
40
|
-
component: React.ReactElement<T>,
|
|
41
|
-
{
|
|
42
|
-
wrapper: Wrapper,
|
|
43
|
-
createNodeMock,
|
|
44
|
-
unstable_validateStringsRenderedWithinText,
|
|
45
|
-
detectHostComponentNames = true,
|
|
46
|
-
}: RenderInternalOptions = {}
|
|
47
|
-
) {
|
|
48
|
-
if (detectHostComponentNames) {
|
|
49
|
-
configureHostComponentNamesIfNeeded();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (unstable_validateStringsRenderedWithinText) {
|
|
53
|
-
return renderWithStringValidation(component, {
|
|
54
|
-
wrapper: Wrapper,
|
|
55
|
-
createNodeMock,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const wrap = (element: React.ReactElement) =>
|
|
60
|
-
Wrapper ? <Wrapper>{element}</Wrapper> : element;
|
|
61
|
-
|
|
62
|
-
const renderer = renderWithAct(
|
|
63
|
-
wrap(component),
|
|
64
|
-
createNodeMock ? { createNodeMock } : undefined
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
return buildRenderResult(renderer, wrap);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function renderWithStringValidation<T>(
|
|
71
|
-
component: React.ReactElement<T>,
|
|
72
|
-
{
|
|
73
|
-
wrapper: Wrapper,
|
|
74
|
-
createNodeMock,
|
|
75
|
-
}: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {}
|
|
76
|
-
) {
|
|
77
|
-
const handleRender: React.ProfilerProps['onRender'] = (_, phase) => {
|
|
78
|
-
if (phase === 'update') {
|
|
79
|
-
validateStringsRenderedWithinText(screen.toJSON());
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const wrap = (element: React.ReactElement) => (
|
|
84
|
-
<Profiler id="renderProfiler" onRender={handleRender}>
|
|
85
|
-
{Wrapper ? <Wrapper>{element}</Wrapper> : element}
|
|
86
|
-
</Profiler>
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const renderer = renderWithAct(
|
|
90
|
-
wrap(component),
|
|
91
|
-
createNodeMock ? { createNodeMock } : undefined
|
|
92
|
-
);
|
|
93
|
-
validateStringsRenderedWithinText(renderer.toJSON());
|
|
94
|
-
|
|
95
|
-
return buildRenderResult(renderer, wrap);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function buildRenderResult(
|
|
99
|
-
renderer: ReactTestRenderer,
|
|
100
|
-
wrap: (element: React.ReactElement) => JSX.Element
|
|
101
|
-
) {
|
|
102
|
-
const update = updateWithAct(renderer, wrap);
|
|
103
|
-
const instance = renderer.root;
|
|
104
|
-
|
|
105
|
-
const unmount = () => {
|
|
106
|
-
act(() => {
|
|
107
|
-
renderer.unmount();
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
addToCleanupQueue(unmount);
|
|
112
|
-
|
|
113
|
-
const result = {
|
|
114
|
-
...getQueriesForElement(instance),
|
|
115
|
-
update,
|
|
116
|
-
unmount,
|
|
117
|
-
rerender: update, // alias for `update`
|
|
118
|
-
toJSON: renderer.toJSON,
|
|
119
|
-
debug: debug(instance, renderer),
|
|
120
|
-
get root(): ReactTestInstance {
|
|
121
|
-
return getHostChildren(instance)[0];
|
|
122
|
-
},
|
|
123
|
-
UNSAFE_root: instance,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// Add as non-enumerable property, so that it's safe to enumerate
|
|
127
|
-
// `render` result, e.g. using destructuring rest syntax.
|
|
128
|
-
Object.defineProperty(result, 'container', {
|
|
129
|
-
enumerable: false,
|
|
130
|
-
get() {
|
|
131
|
-
throw new Error(
|
|
132
|
-
"'container' property has been renamed to 'UNSAFE_root'.\n\n" +
|
|
133
|
-
"Consider using 'root' property which returns root host element."
|
|
134
|
-
);
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
setRenderResult(result);
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function updateWithAct(
|
|
143
|
-
renderer: ReactTestRenderer,
|
|
144
|
-
wrap: (innerElement: React.ReactElement) => React.ReactElement
|
|
145
|
-
) {
|
|
146
|
-
return function (component: React.ReactElement) {
|
|
147
|
-
act(() => {
|
|
148
|
-
renderer.update(wrap(component));
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface DebugFunction {
|
|
154
|
-
(options?: DebugOptions | string): void;
|
|
155
|
-
shallow: (message?: string) => void;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function debug(
|
|
159
|
-
instance: ReactTestInstance,
|
|
160
|
-
renderer: ReactTestRenderer
|
|
161
|
-
): DebugFunction {
|
|
162
|
-
function debugImpl(options?: DebugOptions | string) {
|
|
163
|
-
const { defaultDebugOptions } = getConfig();
|
|
164
|
-
const debugOptions =
|
|
165
|
-
typeof options === 'string'
|
|
166
|
-
? { ...defaultDebugOptions, message: options }
|
|
167
|
-
: { ...defaultDebugOptions, ...options };
|
|
168
|
-
|
|
169
|
-
if (typeof options === 'string') {
|
|
170
|
-
// eslint-disable-next-line no-console
|
|
171
|
-
console.warn(
|
|
172
|
-
'Using debug("message") is deprecated and will be removed in future release, please use debug({ message; "message" }) instead.'
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const json = renderer.toJSON();
|
|
177
|
-
if (json) {
|
|
178
|
-
return debugDeep(json, debugOptions);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
debugImpl.shallow = (message?: string) => debugShallow(instance, message);
|
|
182
|
-
return debugImpl;
|
|
183
|
-
}
|
package/src/renderHook.tsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { ComponentType } from 'react';
|
|
3
|
-
import { renderInternal } from './render';
|
|
4
|
-
|
|
5
|
-
export type RenderHookResult<Result, Props> = {
|
|
6
|
-
rerender: (props: Props) => void;
|
|
7
|
-
result: { current: Result };
|
|
8
|
-
unmount: () => void;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type RenderHookOptions<Props> = {
|
|
12
|
-
initialProps?: Props;
|
|
13
|
-
wrapper?: ComponentType<any>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function renderHook<Result, Props>(
|
|
17
|
-
renderCallback: (props: Props) => Result,
|
|
18
|
-
options?: RenderHookOptions<Props>
|
|
19
|
-
): RenderHookResult<Result, Props> {
|
|
20
|
-
const initialProps = options?.initialProps;
|
|
21
|
-
const wrapper = options?.wrapper;
|
|
22
|
-
|
|
23
|
-
const result: React.MutableRefObject<Result | null> = React.createRef();
|
|
24
|
-
|
|
25
|
-
function TestComponent({
|
|
26
|
-
renderCallbackProps,
|
|
27
|
-
}: {
|
|
28
|
-
renderCallbackProps: Props;
|
|
29
|
-
}) {
|
|
30
|
-
const renderResult = renderCallback(renderCallbackProps);
|
|
31
|
-
|
|
32
|
-
React.useEffect(() => {
|
|
33
|
-
result.current = renderResult;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const { rerender: baseRerender, unmount } = renderInternal(
|
|
40
|
-
// @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt
|
|
41
|
-
<TestComponent renderCallbackProps={initialProps} />,
|
|
42
|
-
{
|
|
43
|
-
wrapper,
|
|
44
|
-
detectHostComponentNames: false,
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
function rerender(rerenderCallbackProps: Props) {
|
|
49
|
-
return baseRerender(
|
|
50
|
-
<TestComponent renderCallbackProps={rerenderCallbackProps} />
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// @ts-expect-error result is ill typed because ref is initialized to null
|
|
55
|
-
return { result, rerender, unmount };
|
|
56
|
-
}
|