@testing-library/react-native 14.0.0-alpha.5 → 14.0.0-beta.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/README.md +18 -7
- package/build/act.d.ts +0 -3
- package/build/act.js +2 -3
- package/build/act.js.map +1 -1
- package/build/config.js +10 -4
- package/build/config.js.map +1 -1
- package/build/event-handler.d.ts +0 -1
- package/build/event-handler.js +0 -1
- package/build/event-handler.js.map +1 -1
- package/build/fire-event.d.ts +2 -11
- package/build/fire-event.js +0 -32
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +1 -1
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +1 -1
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/debug.d.ts +1 -1
- package/build/helpers/debug.js.map +1 -1
- package/build/helpers/errors.d.ts +1 -3
- package/build/helpers/errors.js +3 -36
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/find-all.d.ts +1 -1
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +1 -1
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +1 -1
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-state.d.ts +1 -1
- package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-value.d.ts +1 -1
- package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +1 -1
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +1 -1
- package/build/helpers/matchers/match-text-content.js.map +1 -1
- package/build/helpers/pointer-events.d.ts +1 -1
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/text-content.d.ts +1 -1
- package/build/helpers/text-content.js.map +1 -1
- package/build/helpers/text-input.d.ts +1 -1
- package/build/helpers/text-input.js.map +1 -1
- package/build/helpers/validate-options.d.ts +9 -0
- package/build/helpers/validate-options.js +32 -0
- package/build/helpers/validate-options.js.map +1 -0
- package/build/matchers/to-be-busy.d.ts +1 -1
- package/build/matchers/to-be-busy.js.map +1 -1
- package/build/matchers/to-be-checked.d.ts +1 -1
- package/build/matchers/to-be-checked.js.map +1 -1
- package/build/matchers/to-be-disabled.d.ts +1 -1
- package/build/matchers/to-be-disabled.js.map +1 -1
- package/build/matchers/to-be-empty-element.d.ts +1 -1
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-expanded.d.ts +1 -1
- package/build/matchers/to-be-expanded.js.map +1 -1
- package/build/matchers/to-be-on-the-screen.d.ts +1 -1
- package/build/matchers/to-be-on-the-screen.js.map +1 -1
- package/build/matchers/to-be-partially-checked.d.ts +1 -1
- package/build/matchers/to-be-partially-checked.js.map +1 -1
- package/build/matchers/to-be-selected.d.ts +1 -1
- package/build/matchers/to-be-selected.js.map +1 -1
- package/build/matchers/to-be-visible.d.ts +1 -1
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.d.ts +1 -1
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.d.ts +1 -1
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +1 -1
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.d.ts +1 -1
- package/build/matchers/to-have-display-value.js.map +1 -1
- package/build/matchers/to-have-prop.d.ts +1 -1
- package/build/matchers/to-have-prop.js.map +1 -1
- package/build/matchers/to-have-style.d.ts +1 -1
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +1 -1
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +1 -1
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +1 -1
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +1 -1
- package/build/native-state.js.map +1 -1
- package/build/pure.d.ts +5 -7
- package/build/pure.js +0 -31
- package/build/pure.js.map +1 -1
- package/build/queries/display-value.d.ts +1 -1
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +1 -1
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +1 -1
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +1 -1
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +1 -1
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +1 -1
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +1 -1
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +1 -1
- package/build/queries/text.js.map +1 -1
- package/build/render-hook.d.ts +0 -8
- package/build/render-hook.js +7 -39
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +2 -3
- package/build/render.js +12 -9
- package/build/render.js.map +1 -1
- package/build/screen.js +0 -1
- package/build/screen.js.map +1 -1
- package/build/test-utils/json.d.ts +1 -1
- package/build/test-utils/json.js.map +1 -1
- package/build/test-utils/timers.d.ts +2 -0
- package/build/test-utils/timers.js +20 -0
- package/build/test-utils/timers.js.map +1 -0
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/user-event/clear.d.ts +1 -1
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/event-builder/base.d.ts +5 -1
- package/build/user-event/event-builder/base.js +1 -1
- package/build/user-event/event-builder/base.js.map +1 -1
- package/build/user-event/event-builder/common.d.ts +5 -0
- package/build/user-event/event-builder/index.d.ts +12 -0
- package/build/user-event/event-builder/scroll-view.d.ts +1 -0
- package/build/user-event/event-builder/text-input.d.ts +6 -0
- package/build/user-event/index.d.ts +1 -1
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +1 -1
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.d.ts +1 -1
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +1 -1
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/setup/setup.d.ts +1 -1
- package/build/user-event/setup/setup.js +17 -3
- package/build/user-event/setup/setup.js.map +1 -1
- package/build/user-event/type/type.d.ts +1 -1
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +1 -1
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/wait-for.js +8 -13
- package/build/wait-for.js.map +1 -1
- package/build/within.d.ts +1 -1
- package/build/within.js.map +1 -1
- package/package.json +11 -10
- package/build/react-versions.d.ts +0 -1
- package/build/react-versions.js +0 -14
- package/build/react-versions.js.map +0 -1
- package/build/unsafe-render-sync.d.ts +0 -144
- package/build/unsafe-render-sync.js +0 -114
- package/build/unsafe-render-sync.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,13 +12,15 @@
|
|
|
12
12
|
[![MIT License][license-badge]][license]
|
|
13
13
|
[![Sponsored by Callstack][callstack-badge]][callstack]
|
|
14
14
|
|
|
15
|
+
> ⚠️ **Beta Version:** This version is currently in beta. APIs and behavior may change before the stable release. Please report any issues you encounter.
|
|
16
|
+
|
|
15
17
|
## The problem
|
|
16
18
|
|
|
17
19
|
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
|
|
18
20
|
|
|
19
21
|
## This solution
|
|
20
22
|
|
|
21
|
-
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `
|
|
23
|
+
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
|
|
22
24
|
|
|
23
25
|
> The more your tests resemble the way your software is used, the more confidence they can give you.
|
|
24
26
|
|
|
@@ -30,13 +32,21 @@ Open a Terminal in your project's folder and run:
|
|
|
30
32
|
|
|
31
33
|
```sh
|
|
32
34
|
# Yarn install:
|
|
33
|
-
yarn add --dev @testing-library/react-native
|
|
35
|
+
yarn add --dev @testing-library/react-native@alpha
|
|
34
36
|
|
|
35
37
|
# NPM install
|
|
36
|
-
npm install --save-dev @testing-library/react-native
|
|
38
|
+
npm install --save-dev @testing-library/react-native@alpha
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
This library has a `peerDependencies` listing for
|
|
41
|
+
This library has a `peerDependencies` listing for [Test Renderer](https://github.com/mdjastrzebski/test-renderer). Make sure to install it as a dev dependency:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
# Yarn install:
|
|
45
|
+
yarn add --dev test-renderer
|
|
46
|
+
|
|
47
|
+
# NPM install
|
|
48
|
+
npm install --save-dev test-renderer
|
|
49
|
+
```
|
|
40
50
|
|
|
41
51
|
### Additional Jest matchers
|
|
42
52
|
|
|
@@ -57,7 +67,7 @@ test('form submits two answers', async () => {
|
|
|
57
67
|
const onSubmit = jest.fn();
|
|
58
68
|
|
|
59
69
|
const user = userEvent.setup();
|
|
60
|
-
render(<QuestionsBoard questions={questions} onSubmit={onSubmit} />);
|
|
70
|
+
await render(<QuestionsBoard questions={questions} onSubmit={onSubmit} />);
|
|
61
71
|
|
|
62
72
|
const answerInputs = screen.getAllByLabelText('answer input');
|
|
63
73
|
|
|
@@ -85,9 +95,9 @@ React Native Testing Library consists of following APIs:
|
|
|
85
95
|
- [`screen` object](https://callstack.github.io/react-native-testing-library/docs/api/screen) - access rendered UI:
|
|
86
96
|
- [Queries](https://callstack.github.io/react-native-testing-library/docs/api/queries) - find rendered components by various predicates: role, text, test ids, etc
|
|
87
97
|
- Lifecycle methods: [`rerender`](https://callstack.github.io/react-native-testing-library/docs/api/screen#rerender), [`unmount`](https://callstack.github.io/react-native-testing-library/docs/api/screen#unmount)
|
|
88
|
-
- Helpers: [`debug`](https://callstack.github.io/react-native-testing-library/docs/api/screen#debug), [`toJSON`](https://callstack.github.io/react-native-testing-library/docs/api/screen#tojson), [`root`](https://callstack.github.io/react-native-testing-library/docs/api/screen#root)
|
|
98
|
+
- Helpers: [`debug`](https://callstack.github.io/react-native-testing-library/docs/api/screen#debug), [`toJSON`](https://callstack.github.io/react-native-testing-library/docs/api/screen#tojson), [`root`](https://callstack.github.io/react-native-testing-library/docs/api/screen#root), [`container`](https://callstack.github.io/react-native-testing-library/docs/api/screen#container)
|
|
89
99
|
- [Jest matchers](https://callstack.github.io/react-native-testing-library/docs/api/jest-matchers) - validate assumptions about your UI
|
|
90
|
-
- [User Event](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event) - simulate common user interactions like [`press`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#press) or [`type`](https://callstack.github.io/react-native-testing-library/docs/user-event#type) in a realistic way
|
|
100
|
+
- [User Event](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event) - simulate common user interactions like [`press`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#press) or [`type`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#type) in a realistic way
|
|
91
101
|
- [Fire Event](https://callstack.github.io/react-native-testing-library/docs/api/events/fire-event) - simulate any component event in a simplified way
|
|
92
102
|
- [`renderHook` function](https://callstack.github.io/react-native-testing-library/docs/api/misc/render-hook) - render hooks for testing purposes
|
|
93
103
|
- Miscellaneous APIs:
|
|
@@ -98,6 +108,7 @@ React Native Testing Library consists of following APIs:
|
|
|
98
108
|
|
|
99
109
|
## Migration Guides
|
|
100
110
|
|
|
111
|
+
- **[Migration to 14.0](https://callstack.github.io/react-native-testing-library/docs/migration/v14)** - Drops React 18, async APIs by default
|
|
101
112
|
- [Migration to 13.0](https://callstack.github.io/react-native-testing-library/docs/migration/v13)
|
|
102
113
|
- [Migration to built-in Jest Matchers](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers)
|
|
103
114
|
|
package/build/act.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
type ReactAct = typeof React.act;
|
|
3
1
|
declare global {
|
|
4
2
|
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
5
3
|
}
|
|
6
4
|
declare function setIsReactActEnvironment(isReactActEnvironment: boolean | undefined): void;
|
|
7
5
|
declare function getIsReactActEnvironment(): boolean | undefined;
|
|
8
|
-
export declare const unsafe_act: ReactAct;
|
|
9
6
|
export declare function act<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
10
7
|
export { getIsReactActEnvironment, setIsReactActEnvironment as setReactActEnvironment };
|
package/build/act.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.act = act;
|
|
7
7
|
exports.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
8
8
|
exports.setReactActEnvironment = setIsReactActEnvironment;
|
|
9
|
-
exports.unsafe_act = void 0;
|
|
10
9
|
var React = _interopRequireWildcard(require("react"));
|
|
11
10
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
11
|
// This file and the act() implementation is sourced from react-testing-library
|
|
@@ -65,8 +64,8 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
65
64
|
}
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
|
-
const
|
|
67
|
+
const _act = withGlobalActEnvironment(reactAct);
|
|
69
68
|
function act(callback) {
|
|
70
|
-
return
|
|
69
|
+
return _act(async () => await callback());
|
|
71
70
|
}
|
|
72
71
|
//# sourceMappingURL=act.js.map
|
package/build/act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","reactAct","act","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","
|
|
1
|
+
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","reactAct","act","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","_act"],"sources":["../src/act.ts"],"sourcesContent":["// This file and the act() implementation is sourced from react-testing-library\n// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/types/index.d.ts\nimport * as React from 'react';\n\nconst reactAct = React.act;\ntype ReactAct = typeof React.act;\n\n// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT\ndeclare global {\n var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;\n}\n\nfunction setIsReactActEnvironment(isReactActEnvironment: boolean | undefined) {\n globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;\n}\n\nfunction getIsReactActEnvironment() {\n return globalThis.IS_REACT_ACT_ENVIRONMENT;\n}\n\nfunction withGlobalActEnvironment(actImplementation: ReactAct) {\n return (callback: Parameters<ReactAct>[0]) => {\n const previousActEnvironment = getIsReactActEnvironment();\n setIsReactActEnvironment(true);\n\n try {\n // The return value of `act` is always a thenable.\n let callbackNeedsToBeAwaited = false;\n const actResult = actImplementation(() => {\n const result = callback();\n // @ts-expect-error TS is too strict here\n if (result !== null && typeof result === 'object' && typeof result.then === 'function') {\n callbackNeedsToBeAwaited = true;\n }\n return result;\n });\n\n if (callbackNeedsToBeAwaited) {\n const thenable = actResult;\n return {\n then: (resolve: (value: never) => never, reject: (value: never) => never) => {\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n thenable.then(\n // eslint-disable-next-line promise/always-return\n (returnValue) => {\n setIsReactActEnvironment(previousActEnvironment);\n resolve(returnValue as never);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\n reject(error as never);\n },\n );\n },\n };\n } else {\n setIsReactActEnvironment(previousActEnvironment);\n return actResult;\n }\n } catch (error) {\n // Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT\n // or if we have to await the callback first.\n setIsReactActEnvironment(previousActEnvironment);\n throw error;\n }\n };\n}\n\nconst _act = withGlobalActEnvironment(reactAct) as ReactAct;\n\nexport function act<T>(callback: () => T | Promise<T>): Promise<T> {\n return _act(async () => await callback());\n}\n\nexport { getIsReactActEnvironment, setIsReactActEnvironment as setReactActEnvironment };\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,y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,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EAAE;UACtFH,wBAAwB,GAAG,IAAI;QACjC;QACA,OAAOE,MAAM;MACf,CAAC,CAAC;MAEF,IAAIF,wBAAwB,EAAE;QAC5B,MAAMI,QAAQ,GAAGH,SAAS;QAC1B,OAAO;UACLE,IAAI,EAAEA,CAACE,OAAgC,EAAEC,MAA+B,KAAK;YAC3E;YACAF,QAAQ,CAACD,IAAI;YACX;YACCI,WAAW,IAAK;cACfhB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChDM,OAAO,CAACE,WAAoB,CAAC;YAC/B,CAAC,EACAC,KAAK,IAAK;cACTjB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChDO,MAAM,CAACE,KAAc,CAAC;YACxB,CACF,CAAC;UACH;QACF,CAAC;MACH,CAAC,MAAM;QACLjB,wBAAwB,CAACQ,sBAAsB,CAAC;QAChD,OAAOE,SAAS;MAClB;IACF,CAAC,CAAC,OAAOO,KAAK,EAAE;MACd;MACA;MACAjB,wBAAwB,CAACQ,sBAAsB,CAAC;MAChD,MAAMS,KAAK;IACb;EACF,CAAC;AACH;AAEA,MAAMC,IAAI,GAAGb,wBAAwB,CAACP,QAAQ,CAAa;AAEpD,SAASC,GAAGA,CAAIQ,QAA8B,EAAc;EACjE,OAAOW,IAAI,CAAC,YAAY,MAAMX,QAAQ,CAAC,CAAC,CAAC;AAC3C","ignoreList":[]}
|
package/build/config.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.configure = configure;
|
|
7
7
|
exports.getConfig = getConfig;
|
|
8
8
|
exports.resetToDefaults = resetToDefaults;
|
|
9
|
+
var _validateOptions = require("./helpers/validate-options");
|
|
9
10
|
/**
|
|
10
11
|
* Global configuration options for React Native Testing Library.
|
|
11
12
|
*/
|
|
@@ -23,14 +24,19 @@ let config = {
|
|
|
23
24
|
*/
|
|
24
25
|
function configure(options) {
|
|
25
26
|
const {
|
|
27
|
+
asyncUtilTimeout,
|
|
28
|
+
defaultDebugOptions,
|
|
26
29
|
defaultHidden,
|
|
27
|
-
|
|
30
|
+
defaultIncludeHiddenElements,
|
|
31
|
+
...rest
|
|
28
32
|
} = options;
|
|
29
|
-
|
|
33
|
+
(0, _validateOptions.validateOptions)('configure', rest, configure);
|
|
34
|
+
const resolvedDefaultIncludeHiddenElements = defaultIncludeHiddenElements ?? defaultHidden ?? config.defaultIncludeHiddenElements;
|
|
30
35
|
config = {
|
|
31
36
|
...config,
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
asyncUtilTimeout: asyncUtilTimeout ?? config.asyncUtilTimeout,
|
|
38
|
+
defaultDebugOptions,
|
|
39
|
+
defaultIncludeHiddenElements: resolvedDefaultIncludeHiddenElements
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
42
|
function resetToDefaults() {
|
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultHidden","
|
|
1
|
+
{"version":3,"file":"config.js","names":["_validateOptions","require","defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultDebugOptions","defaultHidden","rest","validateOptions","resolvedDefaultIncludeHiddenElements","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import type { DebugOptions } from './helpers/debug';\nimport { validateOptions } from './helpers/validate-options';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nconst defaultConfig: Config = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const {\n asyncUtilTimeout,\n defaultDebugOptions,\n defaultHidden,\n defaultIncludeHiddenElements,\n ...rest\n } = options;\n\n validateOptions('configure', rest, configure);\n\n const resolvedDefaultIncludeHiddenElements =\n defaultIncludeHiddenElements ?? defaultHidden ?? config.defaultIncludeHiddenElements;\n\n config = {\n ...config,\n asyncUtilTimeout: asyncUtilTimeout ?? config.asyncUtilTimeout,\n defaultDebugOptions,\n defaultIncludeHiddenElements: resolvedDefaultIncludeHiddenElements,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AAEA;AACA;AACA;;AAkBA,MAAMC,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE;AAChC,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGH;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASI,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IACJJ,gBAAgB;IAChBK,mBAAmB;IACnBC,aAAa;IACbL,4BAA4B;IAC5B,GAAGM;EACL,CAAC,GAAGH,OAAO;EAEX,IAAAI,gCAAe,EAAC,WAAW,EAAED,IAAI,EAAEJ,SAAS,CAAC;EAE7C,MAAMM,oCAAoC,GACxCR,4BAA4B,IAAIK,aAAa,IAAIJ,MAAM,CAACD,4BAA4B;EAEtFC,MAAM,GAAG;IACP,GAAGA,MAAM;IACTF,gBAAgB,EAAEA,gBAAgB,IAAIE,MAAM,CAACF,gBAAgB;IAC7DK,mBAAmB;IACnBJ,4BAA4B,EAAEQ;EAChC,CAAC;AACH;AAEO,SAASC,eAAeA,CAAA,EAAG;EAChCR,MAAM,GAAG;IAAE,GAAGH;EAAc,CAAC;AAC/B;AAEO,SAASY,SAASA,CAAA,EAAG;EAC1B,OAAOT,MAAM;AACf","ignoreList":[]}
|
package/build/event-handler.d.ts
CHANGED
|
@@ -4,4 +4,3 @@ export type EventHandlerOptions = {
|
|
|
4
4
|
loose?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare function getEventHandlerFromProps(props: Record<string, unknown>, eventName: string, options?: EventHandlerOptions): EventHandler | undefined;
|
|
7
|
-
export declare function getEventHandlerName(eventName: string): string;
|
package/build/event-handler.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getEventHandlerFromProps = getEventHandlerFromProps;
|
|
7
|
-
exports.getEventHandlerName = getEventHandlerName;
|
|
8
7
|
function getEventHandlerFromProps(props, eventName, options) {
|
|
9
8
|
const handlerName = getEventHandlerName(eventName);
|
|
10
9
|
if (typeof props[handlerName] === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.js","names":["getEventHandlerFromProps","props","eventName","options","handlerName","getEventHandlerName","loose","undefined","capitalizeFirstLetter","str","charAt","toUpperCase","slice"],"sources":["../src/event-handler.ts"],"sourcesContent":["export type EventHandler = (...args: unknown[]) => unknown;\n\nexport type EventHandlerOptions = {\n /** Include check for event handler named without adding `on*` prefix. */\n loose?: boolean;\n};\n\nexport function getEventHandlerFromProps(\n props: Record<string, unknown>,\n eventName: string,\n options?: EventHandlerOptions,\n): EventHandler | undefined {\n const handlerName = getEventHandlerName(eventName);\n if (typeof props[handlerName] === 'function') {\n return props[handlerName] as EventHandler;\n }\n\n if (options?.loose && typeof props[eventName] === 'function') {\n return props[eventName] as EventHandler;\n }\n\n if (typeof props[`testOnly_${handlerName}`] === 'function') {\n return props[`testOnly_${handlerName}`] as EventHandler;\n }\n\n if (options?.loose && typeof props[`testOnly_${eventName}`] === 'function') {\n return props[`testOnly_${eventName}`] as EventHandler;\n }\n\n return undefined;\n}\n\
|
|
1
|
+
{"version":3,"file":"event-handler.js","names":["getEventHandlerFromProps","props","eventName","options","handlerName","getEventHandlerName","loose","undefined","capitalizeFirstLetter","str","charAt","toUpperCase","slice"],"sources":["../src/event-handler.ts"],"sourcesContent":["export type EventHandler = (...args: unknown[]) => unknown;\n\nexport type EventHandlerOptions = {\n /** Include check for event handler named without adding `on*` prefix. */\n loose?: boolean;\n};\n\nexport function getEventHandlerFromProps(\n props: Record<string, unknown>,\n eventName: string,\n options?: EventHandlerOptions,\n): EventHandler | undefined {\n const handlerName = getEventHandlerName(eventName);\n if (typeof props[handlerName] === 'function') {\n return props[handlerName] as EventHandler;\n }\n\n if (options?.loose && typeof props[eventName] === 'function') {\n return props[eventName] as EventHandler;\n }\n\n if (typeof props[`testOnly_${handlerName}`] === 'function') {\n return props[`testOnly_${handlerName}`] as EventHandler;\n }\n\n if (options?.loose && typeof props[`testOnly_${eventName}`] === 'function') {\n return props[`testOnly_${eventName}`] as EventHandler;\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${capitalizeFirstLetter(eventName)}`;\n}\n\nfunction capitalizeFirstLetter(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"],"mappings":";;;;;;AAOO,SAASA,wBAAwBA,CACtCC,KAA8B,EAC9BC,SAAiB,EACjBC,OAA6B,EACH;EAC1B,MAAMC,WAAW,GAAGC,mBAAmB,CAACH,SAAS,CAAC;EAClD,IAAI,OAAOD,KAAK,CAACG,WAAW,CAAC,KAAK,UAAU,EAAE;IAC5C,OAAOH,KAAK,CAACG,WAAW,CAAC;EAC3B;EAEA,IAAID,OAAO,EAAEG,KAAK,IAAI,OAAOL,KAAK,CAACC,SAAS,CAAC,KAAK,UAAU,EAAE;IAC5D,OAAOD,KAAK,CAACC,SAAS,CAAC;EACzB;EAEA,IAAI,OAAOD,KAAK,CAAC,YAAYG,WAAW,EAAE,CAAC,KAAK,UAAU,EAAE;IAC1D,OAAOH,KAAK,CAAC,YAAYG,WAAW,EAAE,CAAC;EACzC;EAEA,IAAID,OAAO,EAAEG,KAAK,IAAI,OAAOL,KAAK,CAAC,YAAYC,SAAS,EAAE,CAAC,KAAK,UAAU,EAAE;IAC1E,OAAOD,KAAK,CAAC,YAAYC,SAAS,EAAE,CAAC;EACvC;EAEA,OAAOK,SAAS;AAClB;AAEA,SAASF,mBAAmBA,CAACH,SAAiB,EAAE;EAC9C,OAAO,KAAKM,qBAAqB,CAACN,SAAS,CAAC,EAAE;AAChD;AAEA,SAASM,qBAAqBA,CAACC,GAAW,EAAE;EAC1C,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC;AACnD","ignoreList":[]}
|
package/build/fire-event.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { PressableProps, ScrollViewProps, TextInputProps, TextProps, ViewProps } from 'react-native';
|
|
2
|
-
import type { HostElement } from '
|
|
2
|
+
import type { HostElement } from 'test-renderer';
|
|
3
3
|
import type { StringWithAutocomplete } from './types';
|
|
4
|
-
export declare function isTouchResponder(element: HostElement): boolean;
|
|
5
|
-
export declare function isEventEnabled(element: HostElement, eventName: string, nearestTouchResponder?: HostElement): boolean;
|
|
6
4
|
type EventNameExtractor<T> = keyof {
|
|
7
5
|
[K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];
|
|
8
6
|
};
|
|
@@ -13,11 +11,4 @@ declare namespace fireEvent {
|
|
|
13
11
|
var changeText: (element: HostElement, ...data: unknown[]) => Promise<undefined>;
|
|
14
12
|
var scroll: (element: HostElement, ...data: unknown[]) => Promise<undefined>;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
declare function unsafe_fireEventSync(element: HostElement, eventName: EventName, ...data: unknown[]): undefined;
|
|
18
|
-
declare namespace unsafe_fireEventSync {
|
|
19
|
-
var press: (element: HostElement, ...data: unknown[]) => undefined;
|
|
20
|
-
var changeText: (element: HostElement, ...data: unknown[]) => undefined;
|
|
21
|
-
var scroll: (element: HostElement, ...data: unknown[]) => undefined;
|
|
22
|
-
}
|
|
23
|
-
export { fireEvent, unsafe_fireEventSync };
|
|
14
|
+
export { fireEvent };
|
package/build/fire-event.js
CHANGED
|
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.fireEvent = fireEvent;
|
|
7
|
-
exports.isEventEnabled = isEventEnabled;
|
|
8
|
-
exports.isTouchResponder = isTouchResponder;
|
|
9
|
-
exports.unsafe_fireEventSync = unsafe_fireEventSync;
|
|
10
7
|
var _act = require("./act");
|
|
11
8
|
var _eventHandler = require("./event-handler");
|
|
12
9
|
var _componentTree = require("./helpers/component-tree");
|
|
@@ -15,9 +12,6 @@ var _pointerEvents = require("./helpers/pointer-events");
|
|
|
15
12
|
var _textInput = require("./helpers/text-input");
|
|
16
13
|
var _nativeState = require("./native-state");
|
|
17
14
|
function isTouchResponder(element) {
|
|
18
|
-
if (!(0, _componentTree.isHostElement)(element)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
15
|
return Boolean(element.props.onStartShouldSetResponder) || (0, _hostComponentNames.isHostTextInput)(element);
|
|
22
16
|
}
|
|
23
17
|
|
|
@@ -102,32 +96,6 @@ async function fireEvent(element, eventName, ...data) {
|
|
|
102
96
|
fireEvent.press = async (element, ...data) => await fireEvent(element, 'press', ...data);
|
|
103
97
|
fireEvent.changeText = async (element, ...data) => await fireEvent(element, 'changeText', ...data);
|
|
104
98
|
fireEvent.scroll = async (element, ...data) => await fireEvent(element, 'scroll', ...data);
|
|
105
|
-
|
|
106
|
-
/** @deprecated - Use async `fireEvent` instead. */
|
|
107
|
-
function unsafe_fireEventSync(element, eventName, ...data) {
|
|
108
|
-
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
setNativeStateIfNeeded(element, eventName, data[0]);
|
|
112
|
-
const handler = findEventHandler(element, eventName);
|
|
113
|
-
if (!handler) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
let returnValue;
|
|
117
|
-
void (0, _act.unsafe_act)(() => {
|
|
118
|
-
returnValue = handler(...data);
|
|
119
|
-
});
|
|
120
|
-
return returnValue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** @deprecated - Use async `fireEvent.press` instead. */
|
|
124
|
-
unsafe_fireEventSync.press = (element, ...data) => unsafe_fireEventSync(element, 'press', ...data);
|
|
125
|
-
|
|
126
|
-
/** @deprecated - Use async `fireEvent.changeText` instead. */
|
|
127
|
-
unsafe_fireEventSync.changeText = (element, ...data) => unsafe_fireEventSync(element, 'changeText', ...data);
|
|
128
|
-
|
|
129
|
-
/** @deprecated - Use async `fireEvent.scroll` instead. */
|
|
130
|
-
unsafe_fireEventSync.scroll = (element, ...data) => unsafe_fireEventSync(element, 'scroll', ...data);
|
|
131
99
|
const scrollEventNames = new Set(['scroll', 'scrollBeginDrag', 'scrollEndDrag', 'momentumScrollBegin', 'momentumScrollEnd']);
|
|
132
100
|
function setNativeStateIfNeeded(element, eventName, value) {
|
|
133
101
|
if (eventName === 'changeText' && typeof value === 'string' && (0, _textInput.isEditableTextInput)(element)) {
|
package/build/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","names":["_act","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandlerFromProps","loose","findEventHandlerFromFiber","unstable_fiber","parent","fiber","memoizedProps","return","type","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","unsafe_fireEventSync","unsafe_act","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { Fiber, HostElement } from 'universal-test-renderer';\n\nimport { act, unsafe_act } from './act';\nimport type { EventHandler } from './event-handler';\nimport { getEventHandlerFromProps } from './event-handler';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\n\nexport function isTouchResponder(element: HostElement) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n) {\n if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler =\n getEventHandlerFromProps(element.props, eventName, { loose: true }) ??\n findEventHandlerFromFiber(element.unstable_fiber, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\n\n if (element.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction findEventHandlerFromFiber(fiber: Fiber | null, eventName: string): EventHandler | null {\n // Container fibers have memoizedProps set to null\n if (!fiber?.memoizedProps) {\n return null;\n }\n\n const handler = getEventHandlerFromProps(fiber.memoizedProps, eventName, { loose: true });\n if (handler) {\n return handler;\n }\n\n // No parent fiber or we reached another host element\n if (fiber.return === null || typeof fiber.return.type === 'string') {\n return null;\n }\n\n return findEventHandlerFromFiber(fiber.return, eventName);\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nasync function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n await act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'scroll', ...data);\n\n/** @deprecated - Use async `fireEvent` instead. */\nfunction unsafe_fireEventSync(element: HostElement, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void unsafe_act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\n/** @deprecated - Use async `fireEvent.press` instead. */\nunsafe_fireEventSync.press = (element: HostElement, ...data: unknown[]) =>\n unsafe_fireEventSync(element, 'press', ...data);\n\n/** @deprecated - Use async `fireEvent.changeText` instead. */\nunsafe_fireEventSync.changeText = (element: HostElement, ...data: unknown[]) =>\n unsafe_fireEventSync(element, 'changeText', ...data);\n\n/** @deprecated - Use async `fireEvent.scroll` instead. */\nunsafe_fireEventSync.scroll = (element: HostElement, ...data: unknown[]) =>\n unsafe_fireEventSync(element, 'scroll', ...data);\n\nexport { fireEvent, unsafe_fireEventSync };\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: HostElement, eventName: string, value: unknown) {\n if (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;AASA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAGO,SAASO,gBAAgBA,CAACC,OAAoB,EAAE;EACrD,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OAAOE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAAoB,EACpBU,SAAiB,EACjBC,qBAAmC,EACnC;EACA,IAAIA,qBAAqB,IAAI,IAAI,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC3E,OACE,IAAAC,8BAAmB,EAACD,qBAAqB,CAAC,IAC1CH,mCAAmC,CAACK,GAAG,CAACH,SAAS,CAAC;EAEtD;EAEA,IAAIJ,iCAAiC,CAACO,GAAG,CAACH,SAAS,CAAC,IAAI,CAAC,IA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2C,KAAK,CAAC;EACjD;EAEA,IAAID,gBAAgB,CAAC7B,GAAG,CAACH,SAAS,CAAC,IAAI,IAAAqC,oCAAgB,EAAC/C,OAAO,CAAC,EAAE;IAChE,MAAMgD,aAAa,GAAGC,mBAAmB,CAACN,KAAK,CAAC;IAChD,IAAIK,aAAa,EAAE;MACjBJ,wBAAW,CAACM,uBAAuB,CAACJ,GAAG,CAAC9C,OAAO,EAAEgD,aAAa,CAAC;IACjE;EACF;AACF;AAEA,SAASC,mBAAmBA,CAACE,KAAc,EAAgB;EACzD,IAAI;IACF;IACA,MAAMH,aAAa,GAAGG,KAAK,EAAEC,WAAW,EAAEJ,aAAa;IACvD,MAAMK,CAAC,GAAGL,aAAa,EAAEK,CAAC;IAC1B,MAAMC,CAAC,GAAGN,aAAa,EAAEM,CAAC;IAC1B,IAAI,OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAO;QACLD,CAAC,EAAEE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC;QAC7BC,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fire-event.js","names":["_act","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","isTouchResponder","element","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandlerFromProps","loose","findEventHandlerFromFiber","unstable_fiber","parent","fiber","memoizedProps","return","type","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { Fiber, HostElement } from 'test-renderer';\n\nimport { act } from './act';\nimport type { EventHandler } from './event-handler';\nimport { getEventHandlerFromProps } from './event-handler';\nimport { isElementMounted } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\n\nfunction isTouchResponder(element: HostElement) {\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nfunction isEventEnabled(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n) {\n if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler =\n getEventHandlerFromProps(element.props, eventName, { loose: true }) ??\n findEventHandlerFromFiber(element.unstable_fiber, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\n\n if (element.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction findEventHandlerFromFiber(fiber: Fiber | null, eventName: string): EventHandler | null {\n // Container fibers have memoizedProps set to null\n if (!fiber?.memoizedProps) {\n return null;\n }\n\n const handler = getEventHandlerFromProps(fiber.memoizedProps, eventName, { loose: true });\n if (handler) {\n return handler;\n }\n\n // No parent fiber or we reached another host element\n if (fiber.return === null || typeof fiber.return.type === 'string') {\n return null;\n }\n\n return findEventHandlerFromFiber(fiber.return, eventName);\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nasync function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n await act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = async (element: HostElement, ...data: unknown[]) =>\n await fireEvent(element, 'scroll', ...data);\n\nexport { fireEvent };\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: HostElement, eventName: string, value: unknown) {\n if (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;AASA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAGA,SAASO,gBAAgBA,CAACC,OAAoB,EAAE;EAC9C,OAAOC,OAAO,CAACD,OAAO,CAACE,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACJ,OAAO,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAA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E1B,IAAI,OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAO;QACLD,CAAC,EAAEE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC;QAC7BC,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';
|
|
2
|
-
import type { HostElement } from '
|
|
2
|
+
import type { HostElement } from 'test-renderer';
|
|
3
3
|
type IsInaccessibleOptions = {
|
|
4
4
|
cache?: WeakMap<HostElement, boolean>;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","container","getContainerElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { HostElement } from 'universal-test-renderer';\n\nimport { getContainerElement, getHostSiblings, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<HostElement, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: HostElement | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: HostElement | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: HostElement): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: HostElement | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: HostElement): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: HostElement): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: HostElement): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const container = getContainerElement(element);\n const labelElement = findAll(\n container,\n (node) => isHostElement(node) && node.props.nativeID === labelElementId,\n { includeHiddenElements: true },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: HostElement): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: HostElement): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: HostElement): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n\n if (isHostText(element) && props.disabled) {\n return true;\n }\n\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: HostElement): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: HostElement): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: HostElement): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: HostElement): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAyBA,CACvCC,OAA2B,EAC3B;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAA2B,GAAGF,OAAO;EACzC,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,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IAC5CC,IAAI,EAAEJ,aAAa,IAAIJ,kBAAkB,EAAEQ;EAC7C,CAAC;AACH;AAEO,SAASC,qBAAqBA,CAAC3E,OAAoB,EAAsB;EAC9E,OAAOoC,gBAAgB,CAACpC,OAAO,CAAC,IAAI,IAAAgD,2BAAc,EAAChD,OAAO,CAAC;AAC7D;AAIO,MAAMwD,2BAA2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","container","getContainerElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { HostElement } from 'test-renderer';\n\nimport { getContainerElement, getHostSiblings, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<HostElement, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: HostElement | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: HostElement | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: HostElement): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: HostElement | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: HostElement): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: HostElement): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: HostElement): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const container = getContainerElement(element);\n const labelElement = findAll(\n container,\n (node) => isHostElement(node) && node.props.nativeID === labelElementId,\n { includeHiddenElements: true },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: HostElement): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: HostElement): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: HostElement): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n\n if (isHostText(element) && props.disabled) {\n return true;\n }\n\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: HostElement): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: HostElement): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: HostElement): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: HostElement): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAyBA,CACvCC,OAA2B,EAC3B;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAA2B,GAAGF,OAAO;EACzC,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ,OAAO,CAAC;MAC7DD,KAAK,EAAEM,GAAG,CAACL,OAAO,EAAEC,4BAA4B,CAAC;IACnD;IAEA,IAAIA,4BAA4B,EAAE;MAChC,OAAO,IAAI;IACb;IAE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2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-tree.js","names":["_screen","require","isHostElement","element","type","isElementMounted","getContainerElement","screen","container","getHostSiblings","parent","children","filter","sibling","current"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import type { HostElement, HostNode } from '
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["_screen","require","isHostElement","element","type","isElementMounted","getContainerElement","screen","container","getHostSiblings","parent","children","filter","sibling","current"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import type { HostElement, HostNode } from 'test-renderer';\n\nimport { screen } from '../screen';\n\n/**\n * Checks if the given element is a host element.\n * @param element The element to check.\n */\nexport function isHostElement(element?: HostNode | null): element is HostElement {\n return typeof element !== 'string' && typeof element?.type === 'string';\n}\n\nexport function isElementMounted(element: HostElement) {\n return getContainerElement(element) === screen.container;\n}\n\n/**\n * Returns host siblings for given element.\n * @param element The element start traversing from.\n */\nexport function getHostSiblings(element: HostElement): HostElement[] {\n // Should not happen\n const parent = element.parent;\n if (!parent) {\n return [];\n }\n\n return parent.children.filter(\n (sibling) => typeof sibling !== 'string' && sibling !== element,\n ) as HostElement[];\n}\n\n/**\n * Returns the containerelement of the tree.\n *\n * @param element The element start traversing from.\n * @returns The container element of the tree.\n */\nexport function getContainerElement(element: HostElement) {\n let current = element;\n while (current.parent) {\n current = current.parent;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,OAAyB,EAA0B;EAC/E,OAAO,OAAOA,OAAO,KAAK,QAAQ,IAAI,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AACzE;AAEO,SAASC,gBAAgBA,CAACF,OAAoB,EAAE;EACrD,OAAOG,mBAAmB,CAACH,OAAO,CAAC,KAAKI,cAAM,CAACC,SAAS;AAC1D;;AAEA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACN,OAAoB,EAAiB;EACnE;EACA,MAAMO,MAAM,GAAGP,OAAO,CAACO,MAAM;EAC7B,IAAI,CAACA,MAAM,EAAE;IACX,OAAO,EAAE;EACX;EAEA,OAAOA,MAAM,CAACC,QAAQ,CAACC,MAAM,CAC1BC,OAAO,IAAK,OAAOA,OAAO,KAAK,QAAQ,IAAIA,OAAO,KAAKV,OAC1D,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,mBAAmBA,CAACH,OAAoB,EAAE;EACxD,IAAIW,OAAO,GAAGX,OAAO;EACrB,OAAOW,OAAO,CAACJ,MAAM,EAAE;IACrBI,OAAO,GAAGA,OAAO,CAACJ,MAAM;EAC1B;EAEA,OAAOI,OAAO;AAChB","ignoreList":[]}
|
package/build/helpers/debug.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","names":["_formatElement","require","_logger","debug","node","message","formatOptions","logger","info","formatJson"],"sources":["../../src/helpers/debug.ts"],"sourcesContent":["import type { JsonNode } from '
|
|
1
|
+
{"version":3,"file":"debug.js","names":["_formatElement","require","_logger","debug","node","message","formatOptions","logger","info","formatJson"],"sources":["../../src/helpers/debug.ts"],"sourcesContent":["import type { JsonNode } from 'test-renderer';\n\nimport type { FormatElementOptions } from './format-element';\nimport { formatJson } from './format-element';\nimport { logger } from './logger';\n\nexport type DebugOptions = {\n message?: string;\n} & FormatElementOptions;\n\n/**\n * Log pretty-printed deep test component instance\n */\nexport function debug(\n node: JsonNode | JsonNode[],\n { message, ...formatOptions }: DebugOptions = {},\n) {\n if (message) {\n logger.info(`${message}\\n\\n`, formatJson(node, formatOptions));\n } else {\n logger.info(formatJson(node, formatOptions));\n }\n}\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACO,SAASE,KAAKA,CACnBC,IAA2B,EAC3B;EAAEC,OAAO;EAAE,GAAGC;AAA4B,CAAC,GAAG,CAAC,CAAC,EAChD;EACA,IAAID,OAAO,EAAE;IACXE,cAAM,CAACC,IAAI,CAAC,GAAGH,OAAO,MAAM,EAAE,IAAAI,yBAAU,EAACL,IAAI,EAAEE,aAAa,CAAC,CAAC;EAChE,CAAC,MAAM;IACLC,cAAM,CAACC,IAAI,CAAC,IAAAC,yBAAU,EAACL,IAAI,EAAEE,aAAa,CAAC,CAAC;EAC9C;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare class ErrorWithStack extends Error {
|
|
2
2
|
constructor(message: string | undefined, callsite: Function);
|
|
3
3
|
}
|
|
4
|
-
export declare
|
|
5
|
-
export declare const createQueryByError: (error: unknown, callsite: Function) => null;
|
|
6
|
-
export declare function copyStackTrace(target: unknown, stackTraceSource: Error): void;
|
|
4
|
+
export declare function copyStackTraceIfNeeded(target: unknown, stackTraceSource: Error | undefined): void;
|
package/build/helpers/errors.js
CHANGED
|
@@ -4,10 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ErrorWithStack = void 0;
|
|
7
|
-
exports.
|
|
8
|
-
exports.prepareErrorMessage = exports.createQueryByError = void 0;
|
|
9
|
-
var _prettyFormat = _interopRequireDefault(require("pretty-format"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
exports.copyStackTraceIfNeeded = copyStackTraceIfNeeded;
|
|
11
8
|
class ErrorWithStack extends Error {
|
|
12
9
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
13
10
|
constructor(message, callsite) {
|
|
@@ -18,38 +15,8 @@ class ErrorWithStack extends Error {
|
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
exports.ErrorWithStack = ErrorWithStack;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (error instanceof Error) {
|
|
24
|
-
// Strip info about custom predicate
|
|
25
|
-
errorMessage = error.message.replace(/ matching custom predicate[^]*/gm, '');
|
|
26
|
-
} else if (error && typeof error === 'object') {
|
|
27
|
-
errorMessage = error.toString();
|
|
28
|
-
} else {
|
|
29
|
-
errorMessage = 'Caught unknown error';
|
|
30
|
-
}
|
|
31
|
-
if (name && value) {
|
|
32
|
-
errorMessage += ` with ${name} ${(0, _prettyFormat.default)(value, {
|
|
33
|
-
min: true
|
|
34
|
-
})}`;
|
|
35
|
-
}
|
|
36
|
-
return errorMessage;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
40
|
-
exports.prepareErrorMessage = prepareErrorMessage;
|
|
41
|
-
const createQueryByError = (error, callsite) => {
|
|
42
|
-
if (error instanceof Error) {
|
|
43
|
-
if (error.message.includes('No instances found')) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
throw new ErrorWithStack(error.message, callsite);
|
|
47
|
-
}
|
|
48
|
-
throw new ErrorWithStack(`Query: caught unknown error type: ${typeof error}, value: ${error}`, callsite);
|
|
49
|
-
};
|
|
50
|
-
exports.createQueryByError = createQueryByError;
|
|
51
|
-
function copyStackTrace(target, stackTraceSource) {
|
|
52
|
-
if (target instanceof Error && stackTraceSource.stack) {
|
|
18
|
+
function copyStackTraceIfNeeded(target, stackTraceSource) {
|
|
19
|
+
if (stackTraceSource != null && target instanceof Error && stackTraceSource.stack) {
|
|
53
20
|
target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);
|
|
54
21
|
}
|
|
55
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["
|
|
1
|
+
{"version":3,"file":"errors.js","names":["ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","exports","copyStackTraceIfNeeded","target","stackTraceSource","stack","replace"],"sources":["../../src/helpers/errors.ts"],"sourcesContent":["export class ErrorWithStack extends Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport function copyStackTraceIfNeeded(target: unknown, stackTraceSource: Error | undefined) {\n if (stackTraceSource != null && target instanceof Error && stackTraceSource.stack) {\n target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);\n }\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,cAAc,SAASC,KAAK,CAAC;EACxC;EACAC,WAAWA,CAACC,OAA2B,EAAEC,QAAkB,EAAE;IAC3D,KAAK,CAACD,OAAO,CAAC;IACd,IAAIF,KAAK,CAACI,iBAAiB,EAAE;MAC3BJ,KAAK,CAACI,iBAAiB,CAAC,IAAI,EAAED,QAAQ,CAAC;IACzC;EACF;AACF;AAACE,OAAA,CAAAN,cAAA,GAAAA,cAAA;AAEM,SAASO,sBAAsBA,CAACC,MAAe,EAAEC,gBAAmC,EAAE;EAC3F,IAAIA,gBAAgB,IAAI,IAAI,IAAID,MAAM,YAAYP,KAAK,IAAIQ,gBAAgB,CAACC,KAAK,EAAE;IACjFF,MAAM,CAACE,KAAK,GAAGD,gBAAgB,CAACC,KAAK,CAACC,OAAO,CAACF,gBAAgB,CAACN,OAAO,EAAEK,MAAM,CAACL,OAAO,CAAC;EACzF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-all.js","names":["_config","require","_accessibility","findAll","root","predicate","options","matchDeepestOnly","results","queryAll","includeHiddenElements","hidden","getConfig","defaultIncludeHiddenElements","cache","WeakMap","filter","element","isHiddenFromAccessibility"],"sources":["../../src/helpers/find-all.ts"],"sourcesContent":["import type { HostElement } from '
|
|
1
|
+
{"version":3,"file":"find-all.js","names":["_config","require","_accessibility","findAll","root","predicate","options","matchDeepestOnly","results","queryAll","includeHiddenElements","hidden","getConfig","defaultIncludeHiddenElements","cache","WeakMap","filter","element","isHiddenFromAccessibility"],"sources":["../../src/helpers/find-all.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport { getConfig } from '../config';\nimport { isHiddenFromAccessibility } from './accessibility';\n\ninterface FindAllOptions {\n /** Match elements hidden from accessibility */\n includeHiddenElements?: boolean;\n\n /** RTL-compatible alias to `includeHiddenElements` */\n hidden?: boolean;\n\n /* Exclude any ancestors of deepest matched elements even if they match the predicate */\n matchDeepestOnly?: boolean;\n}\n\nexport function findAll(\n root: HostElement,\n predicate: (element: HostElement) => boolean,\n options: FindAllOptions = {},\n): HostElement[] {\n const { matchDeepestOnly } = options;\n const results = root.queryAll(predicate, { matchDeepestOnly });\n\n const includeHiddenElements =\n options?.includeHiddenElements ?? options?.hidden ?? getConfig()?.defaultIncludeHiddenElements;\n\n if (includeHiddenElements) {\n return results;\n }\n\n const cache = new WeakMap<HostElement>();\n return results.filter((element) => !isHiddenFromAccessibility(element, { cache }));\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAaO,SAASE,OAAOA,CACrBC,IAAiB,EACjBC,SAA4C,EAC5CC,OAAuB,GAAG,CAAC,CAAC,EACb;EACf,MAAM;IAAEC;EAAiB,CAAC,GAAGD,OAAO;EACpC,MAAME,OAAO,GAAGJ,IAAI,CAACK,QAAQ,CAACJ,SAAS,EAAE;IAAEE;EAAiB,CAAC,CAAC;EAE9D,MAAMG,qBAAqB,GACzBJ,OAAO,EAAEI,qBAAqB,IAAIJ,OAAO,EAAEK,MAAM,IAAI,IAAAC,iBAAS,EAAC,CAAC,EAAEC,4BAA4B;EAEhG,IAAIH,qBAAqB,EAAE;IACzB,OAAOF,OAAO;EAChB;EAEA,MAAMM,KAAK,GAAG,IAAIC,OAAO,CAAc,CAAC;EACxC,OAAOP,OAAO,CAACQ,MAAM,CAAEC,OAAO,IAAK,CAAC,IAAAC,wCAAyB,EAACD,OAAO,EAAE;IAAEH;EAAM,CAAC,CAAC,CAAC;AACpF","ignoreList":[]}
|