@testing-library/react-native 14.0.0-alpha.4 → 14.0.0-alpha.6
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 +2 -2
- package/build/act.d.ts +1 -4
- package/build/act.js +5 -3
- package/build/act.js.map +1 -1
- package/build/cleanup.d.ts +3 -5
- package/build/cleanup.js +2 -8
- package/build/cleanup.js.map +1 -1
- package/build/fire-event.d.ts +3 -10
- package/build/fire-event.js +7 -29
- 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/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 +2 -1
- package/build/helpers/host-component-names.js +2 -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/timers.d.ts +3 -1
- package/build/helpers/timers.js +3 -1
- package/build/helpers/timers.js.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- 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 +10 -12
- package/build/pure.js +12 -45
- 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 +3 -4
- 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 +3 -42
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +7 -77
- package/build/render.js +26 -42
- package/build/render.js.map +1 -1
- package/build/screen.js +1 -5
- 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/tsconfig.release.tsbuildinfo +1 -1
- package/build/types.js +4 -0
- package/build/user-event/clear.d.ts +1 -1
- package/build/user-event/clear.js.map +1 -1
- 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 +2 -3
- 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.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 +2 -5
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/user-event/utils/text-range.js +4 -0
- package/build/wait-for-element-to-be-removed.d.ts +1 -1
- package/build/wait-for-element-to-be-removed.js +3 -4
- package/build/wait-for-element-to-be-removed.js.map +1 -1
- package/build/wait-for.d.ts +1 -1
- package/build/wait-for.js +6 -7
- 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 +18 -20
- package/build/index.flow.js +0 -378
- package/build/render-act.d.ts +0 -3
- package/build/render-act.js +0 -29
- package/build/render-act.js.map +0 -1
- package/build/render-async.d.ts +0 -83
- package/build/render-async.js +0 -96
- package/build/render-async.js.map +0 -1
- package/typings/index.flow.js +0 -378
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ You want to write maintainable tests for your React Native components. As a part
|
|
|
18
18
|
|
|
19
19
|
## This solution
|
|
20
20
|
|
|
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 `
|
|
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 `test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
|
|
22
22
|
|
|
23
23
|
> The more your tests resemble the way your software is used, the more confidence they can give you.
|
|
24
24
|
|
|
@@ -36,7 +36,7 @@ yarn add --dev @testing-library/react-native
|
|
|
36
36
|
npm install --save-dev @testing-library/react-native
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
This library has a `peerDependencies` listing for `
|
|
39
|
+
This library has a `peerDependencies` listing for `test-renderer`. Make sure that your `test-renderer` version matches exactly the `react` version, avoid using `^` in version number.
|
|
40
40
|
|
|
41
41
|
### Additional Jest matchers
|
|
42
42
|
|
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
|
-
declare
|
|
9
|
-
export default act;
|
|
6
|
+
export declare function act<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
10
7
|
export { getIsReactActEnvironment, setIsReactActEnvironment as setReactActEnvironment };
|
package/build/act.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.act = act;
|
|
7
7
|
exports.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
8
8
|
exports.setReactActEnvironment = setIsReactActEnvironment;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
@@ -64,6 +64,8 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const _act = withGlobalActEnvironment(reactAct);
|
|
68
|
+
function act(callback) {
|
|
69
|
+
return _act(async () => await callback());
|
|
70
|
+
}
|
|
69
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,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,I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AAwB,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/cleanup.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
type CleanUpFunction = () => void;
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export declare function cleanupAsync(): Promise<void>;
|
|
5
|
-
export declare function addToCleanupQueue(fn: CleanUpFunction | CleanUpFunctionAsync): void;
|
|
1
|
+
type CleanUpFunction = () => Promise<void> | void;
|
|
2
|
+
export declare function cleanup(): Promise<void>;
|
|
3
|
+
export declare function addToCleanupQueue(fn: CleanUpFunction): void;
|
|
6
4
|
export {};
|
package/build/cleanup.js
CHANGED
|
@@ -4,16 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.addToCleanupQueue = addToCleanupQueue;
|
|
7
|
-
exports.
|
|
8
|
-
exports.default = cleanup;
|
|
7
|
+
exports.cleanup = cleanup;
|
|
9
8
|
var _screen = require("./screen");
|
|
10
9
|
const cleanupQueue = new Set();
|
|
11
|
-
function cleanup() {
|
|
12
|
-
(0, _screen.clearRenderResult)();
|
|
13
|
-
cleanupQueue.forEach(fn => fn());
|
|
14
|
-
cleanupQueue.clear();
|
|
15
|
-
}
|
|
16
|
-
async function cleanupAsync() {
|
|
10
|
+
async function cleanup() {
|
|
17
11
|
(0, _screen.clearRenderResult)();
|
|
18
12
|
for (const fn of cleanupQueue) {
|
|
19
13
|
await fn();
|
package/build/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.js","names":["_screen","require","cleanupQueue","Set","cleanup","clearRenderResult","
|
|
1
|
+
{"version":3,"file":"cleanup.js","names":["_screen","require","cleanupQueue","Set","cleanup","clearRenderResult","fn","clear","addToCleanupQueue","add"],"sources":["../src/cleanup.ts"],"sourcesContent":["import { clearRenderResult } from './screen';\n\ntype CleanUpFunction = () => Promise<void> | void;\n\nconst cleanupQueue = new Set<CleanUpFunction>();\n\nexport async function cleanup() {\n clearRenderResult();\n\n for (const fn of cleanupQueue) {\n await fn();\n }\n\n cleanupQueue.clear();\n}\n\nexport function addToCleanupQueue(fn: CleanUpFunction) {\n cleanupQueue.add(fn);\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIA,MAAMC,YAAY,GAAG,IAAIC,GAAG,CAAkB,CAAC;AAExC,eAAeC,OAAOA,CAAA,EAAG;EAC9B,IAAAC,yBAAiB,EAAC,CAAC;EAEnB,KAAK,MAAMC,EAAE,IAAIJ,YAAY,EAAE;IAC7B,MAAMI,EAAE,CAAC,CAAC;EACZ;EAEAJ,YAAY,CAACK,KAAK,CAAC,CAAC;AACtB;AAEO,SAASC,iBAAiBA,CAACF,EAAmB,EAAE;EACrDJ,YAAY,CAACO,GAAG,CAACH,EAAE,CAAC;AACtB","ignoreList":[]}
|
package/build/fire-event.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
export declare function isTouchResponder(element: HostElement): boolean;
|
|
5
5
|
export declare function isEventEnabled(element: HostElement, eventName: string, nearestTouchResponder?: HostElement): boolean;
|
|
@@ -7,17 +7,10 @@ type EventNameExtractor<T> = keyof {
|
|
|
7
7
|
[K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];
|
|
8
8
|
};
|
|
9
9
|
type EventName = StringWithAutocomplete<EventNameExtractor<ViewProps> | EventNameExtractor<TextProps> | EventNameExtractor<TextInputProps> | EventNameExtractor<PressableProps> | EventNameExtractor<ScrollViewProps>>;
|
|
10
|
-
declare function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]): undefined
|
|
10
|
+
declare function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]): Promise<undefined>;
|
|
11
11
|
declare namespace fireEvent {
|
|
12
|
-
var press: (element: HostElement, ...data: unknown[]) => undefined;
|
|
13
|
-
var changeText: (element: HostElement, ...data: unknown[]) => undefined;
|
|
14
|
-
var scroll: (element: HostElement, ...data: unknown[]) => undefined;
|
|
15
|
-
}
|
|
16
|
-
declare function fireEventAsync(element: HostElement, eventName: EventName, ...data: unknown[]): Promise<undefined>;
|
|
17
|
-
declare namespace fireEventAsync {
|
|
18
12
|
var press: (element: HostElement, ...data: unknown[]) => Promise<undefined>;
|
|
19
13
|
var changeText: (element: HostElement, ...data: unknown[]) => Promise<undefined>;
|
|
20
14
|
var scroll: (element: HostElement, ...data: unknown[]) => Promise<undefined>;
|
|
21
15
|
}
|
|
22
|
-
export {
|
|
23
|
-
export default fireEvent;
|
|
16
|
+
export { fireEvent };
|
package/build/fire-event.js
CHANGED
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.fireEventAsync = fireEventAsync;
|
|
6
|
+
exports.fireEvent = fireEvent;
|
|
8
7
|
exports.isEventEnabled = isEventEnabled;
|
|
9
8
|
exports.isTouchResponder = isTouchResponder;
|
|
10
|
-
var _act =
|
|
9
|
+
var _act = require("./act");
|
|
11
10
|
var _eventHandler = require("./event-handler");
|
|
12
11
|
var _componentTree = require("./helpers/component-tree");
|
|
13
12
|
var _hostComponentNames = require("./helpers/host-component-names");
|
|
14
13
|
var _pointerEvents = require("./helpers/pointer-events");
|
|
15
14
|
var _textInput = require("./helpers/text-input");
|
|
16
15
|
var _nativeState = require("./native-state");
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
16
|
function isTouchResponder(element) {
|
|
19
17
|
if (!(0, _componentTree.isHostElement)(element)) {
|
|
20
18
|
return false;
|
|
@@ -85,7 +83,7 @@ function findEventHandlerFromFiber(fiber, eventName) {
|
|
|
85
83
|
|
|
86
84
|
// String union type of keys of T that start with on, stripped of 'on'
|
|
87
85
|
|
|
88
|
-
function fireEvent(element, eventName, ...data) {
|
|
86
|
+
async function fireEvent(element, eventName, ...data) {
|
|
89
87
|
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
90
88
|
return;
|
|
91
89
|
}
|
|
@@ -95,34 +93,14 @@ function fireEvent(element, eventName, ...data) {
|
|
|
95
93
|
return;
|
|
96
94
|
}
|
|
97
95
|
let returnValue;
|
|
98
|
-
|
|
96
|
+
await (0, _act.act)(() => {
|
|
99
97
|
returnValue = handler(...data);
|
|
100
98
|
});
|
|
101
99
|
return returnValue;
|
|
102
100
|
}
|
|
103
|
-
fireEvent.press = (element, ...data) => fireEvent(element, 'press', ...data);
|
|
104
|
-
fireEvent.changeText = (element, ...data) => fireEvent(element, 'changeText', ...data);
|
|
105
|
-
fireEvent.scroll = (element, ...data) => fireEvent(element, 'scroll', ...data);
|
|
106
|
-
async function fireEventAsync(element, eventName, ...data) {
|
|
107
|
-
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
setNativeStateIfNeeded(element, eventName, data[0]);
|
|
111
|
-
const handler = findEventHandler(element, eventName);
|
|
112
|
-
if (!handler) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
let returnValue;
|
|
116
|
-
// eslint-disable-next-line require-await
|
|
117
|
-
await (0, _act.default)(async () => {
|
|
118
|
-
returnValue = handler(...data);
|
|
119
|
-
});
|
|
120
|
-
return returnValue;
|
|
121
|
-
}
|
|
122
|
-
fireEventAsync.press = async (element, ...data) => await fireEventAsync(element, 'press', ...data);
|
|
123
|
-
fireEventAsync.changeText = async (element, ...data) => await fireEventAsync(element, 'changeText', ...data);
|
|
124
|
-
fireEventAsync.scroll = async (element, ...data) => await fireEventAsync(element, 'scroll', ...data);
|
|
125
|
-
var _default = exports.default = fireEvent;
|
|
101
|
+
fireEvent.press = async (element, ...data) => await fireEvent(element, 'press', ...data);
|
|
102
|
+
fireEvent.changeText = async (element, ...data) => await fireEvent(element, 'changeText', ...data);
|
|
103
|
+
fireEvent.scroll = async (element, ...data) => await fireEvent(element, 'scroll', ...data);
|
|
126
104
|
const scrollEventNames = new Set(['scroll', 'scrollBeginDrag', 'scrollEndDrag', 'momentumScrollBegin', 'momentumScrollEnd']);
|
|
127
105
|
function setNativeStateIfNeeded(element, eventName, value) {
|
|
128
106
|
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","_interopRequireDefault","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","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","fireEventAsync","_default","exports","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 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\nfunction 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 void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: HostElement, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: HostElement, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: HostElement, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nasync function fireEventAsync(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 // eslint-disable-next-line require-await\n await act(async () => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEventAsync.press = async (element: HostElement, ...data: unknown[]) =>\n await fireEventAsync(element, 'press', ...data);\n\nfireEventAsync.changeText = async (element: HostElement, ...data: unknown[]) =>\n await fireEventAsync(element, 'changeText', ...data);\n\nfireEventAsync.scroll = async (element: HostElement, ...data: unknown[]) =>\n await fireEventAsync(element, 'scroll', ...data);\n\nexport { fireEventAsync };\nexport default 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 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,sBAAA,CAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAA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,mBAAmB,CAACN,KAAK,CAAC;IAChD,IAAIK,aAAa,EAAE;MACjBJ,wBAAW,CAACM,uBAAuB,CAACJ,GAAG,CAAC/C,OAAO,EAAEiD,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","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","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, 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\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 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,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,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,OAAO,CAAC;IAEt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AEJ,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;IAEAD,OAAO,GAAGA,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,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 +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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-element.js","names":["_prettyFormat","_interopRequireWildcard","require","_mapProps","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","formatElement","element","compact","highlight","mapProps","defaultMapProps","children","props","childrenToDisplay","undefined","prettyFormat","$$typeof","Symbol","for","type","plugins","ReactTestComponent","ReactElement","printFunctionName","printBasicPrototype","min","formatElementList","elements","options","length","map","join","formatJson","json","getElementJsonPlugin","test","val","serialize","config","indentation","depth","refs","printer","newVal"],"sources":["../../src/helpers/format-element.ts"],"sourcesContent":["import type { NewPlugin } from 'pretty-format';\nimport prettyFormat, { plugins } from 'pretty-format';\nimport type { HostElement, JsonNode } from '
|
|
1
|
+
{"version":3,"file":"format-element.js","names":["_prettyFormat","_interopRequireWildcard","require","_mapProps","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","formatElement","element","compact","highlight","mapProps","defaultMapProps","children","props","childrenToDisplay","undefined","prettyFormat","$$typeof","Symbol","for","type","plugins","ReactTestComponent","ReactElement","printFunctionName","printBasicPrototype","min","formatElementList","elements","options","length","map","join","formatJson","json","getElementJsonPlugin","test","val","serialize","config","indentation","depth","refs","printer","newVal"],"sources":["../../src/helpers/format-element.ts"],"sourcesContent":["import type { NewPlugin } from 'pretty-format';\nimport prettyFormat, { plugins } from 'pretty-format';\nimport type { HostElement, JsonNode } from 'test-renderer';\n\nimport type { MapPropsFunction } from './map-props';\nimport { defaultMapProps } from './map-props';\n\nexport type FormatElementOptions = {\n /** Minimize used space. */\n compact?: boolean;\n\n /** Highlight the output. */\n highlight?: boolean;\n\n /** Filter or map props to display. */\n mapProps?: MapPropsFunction | null;\n};\n\n/***\n * Format given element as a pretty-printed string.\n *\n * @param element Element to format.\n */\nexport function formatElement(\n element: HostElement | null,\n { compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {},\n) {\n if (element == null) {\n return '(null)';\n }\n\n const { children, ...props } = element.props;\n const childrenToDisplay = typeof children === 'string' ? [children] : undefined;\n\n return prettyFormat(\n {\n // This prop is needed persuade the prettyFormat that the element is\n // a JsonNode instance, so it is formatted as JSX.\n $$typeof: Symbol.for('react.test.json'),\n type: `${element.type}`,\n props: mapProps ? mapProps(props) : props,\n children: childrenToDisplay,\n },\n // See: https://www.npmjs.com/package/pretty-format#usage-with-options\n {\n plugins: [plugins.ReactTestComponent, plugins.ReactElement],\n printFunctionName: false,\n printBasicPrototype: false,\n highlight: highlight,\n min: compact,\n },\n );\n}\n\nexport function formatElementList(elements: HostElement[], options?: FormatElementOptions) {\n if (elements.length === 0) {\n return '(no elements)';\n }\n\n return elements.map((element) => formatElement(element, options)).join('\\n');\n}\n\nexport function formatJson(\n json: JsonNode | JsonNode[],\n { compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {},\n) {\n return prettyFormat(json, {\n plugins: [getElementJsonPlugin(mapProps), plugins.ReactElement],\n highlight: highlight,\n printBasicPrototype: false,\n min: compact,\n });\n}\n\nfunction getElementJsonPlugin(mapProps?: MapPropsFunction | null): NewPlugin {\n return {\n test: (val) => plugins.ReactTestComponent.test(val),\n serialize: (val, config, indentation, depth, refs, printer) => {\n let newVal = val;\n if (mapProps && val.props) {\n newVal = { ...val, props: mapProps(val.props) };\n }\n return plugins.ReactTestComponent.serialize(\n newVal,\n config,\n indentation,\n depth,\n refs,\n printer,\n );\n },\n };\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AAA8C,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,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,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,C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,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.HOST_TEXT_NAMES = void 0;
|
|
6
7
|
exports.isHostImage = isHostImage;
|
|
7
8
|
exports.isHostModal = isHostModal;
|
|
8
9
|
exports.isHostScrollView = isHostScrollView;
|
|
9
10
|
exports.isHostSwitch = isHostSwitch;
|
|
10
11
|
exports.isHostText = isHostText;
|
|
11
12
|
exports.isHostTextInput = isHostTextInput;
|
|
12
|
-
const HOST_TEXT_NAMES = ['Text', 'RCTText'];
|
|
13
|
+
const HOST_TEXT_NAMES = exports.HOST_TEXT_NAMES = ['Text', 'RCTText'];
|
|
13
14
|
const HOST_TEXT_INPUT_NAMES = ['TextInput'];
|
|
14
15
|
const HOST_IMAGE_NAMES = ['Image'];
|
|
15
16
|
const HOST_SWITCH_NAMES = ['RCTSwitch'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-component-names.js","names":["HOST_TEXT_NAMES","HOST_TEXT_INPUT_NAMES","HOST_IMAGE_NAMES","HOST_SWITCH_NAMES","HOST_SCROLL_VIEW_NAMES","HOST_MODAL_NAMES","isHostText","element","type","includes","isHostTextInput","isHostImage","isHostSwitch","isHostScrollView","isHostModal"],"sources":["../../src/helpers/host-component-names.ts"],"sourcesContent":["import type { HostElement } from '
|
|
1
|
+
{"version":3,"file":"host-component-names.js","names":["HOST_TEXT_NAMES","exports","HOST_TEXT_INPUT_NAMES","HOST_IMAGE_NAMES","HOST_SWITCH_NAMES","HOST_SCROLL_VIEW_NAMES","HOST_MODAL_NAMES","isHostText","element","type","includes","isHostTextInput","isHostImage","isHostSwitch","isHostScrollView","isHostModal"],"sources":["../../src/helpers/host-component-names.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nexport const HOST_TEXT_NAMES = ['Text', 'RCTText'];\nconst HOST_TEXT_INPUT_NAMES = ['TextInput'];\nconst HOST_IMAGE_NAMES = ['Image'];\nconst HOST_SWITCH_NAMES = ['RCTSwitch'];\nconst HOST_SCROLL_VIEW_NAMES = ['RCTScrollView'];\nconst HOST_MODAL_NAMES = ['Modal'];\n\n/**\n * Checks if the given element is a host Text element.\n * @param element The element to check.\n */\nexport function isHostText(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_TEXT_NAMES.includes(element.type);\n}\n\n/**\n * Checks if the given element is a host TextInput element.\n * @param element The element to check.\n */\nexport function isHostTextInput(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_TEXT_INPUT_NAMES.includes(element.type);\n}\n\n/**\n * Checks if the given element is a host Image element.\n * @param element The element to check.\n */\nexport function isHostImage(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_IMAGE_NAMES.includes(element.type);\n}\n\n/**\n * Checks if the given element is a host Switch element.\n * @param element The element to check.\n */\nexport function isHostSwitch(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_SWITCH_NAMES.includes(element.type);\n}\n\n/**\n * Checks if the given element is a host ScrollView element.\n * @param element The element to check.\n */\nexport function isHostScrollView(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_SCROLL_VIEW_NAMES.includes(element.type);\n}\n\n/**\n * Checks if the given element is a host Modal element.\n * @param element The element to check.\n */\nexport function isHostModal(element: HostElement | null) {\n return typeof element?.type === 'string' && HOST_MODAL_NAMES.includes(element.type);\n}\n"],"mappings":";;;;;;;;;;;;AAEO,MAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC;AAClD,MAAME,qBAAqB,GAAG,CAAC,WAAW,CAAC;AAC3C,MAAMC,gBAAgB,GAAG,CAAC,OAAO,CAAC;AAClC,MAAMC,iBAAiB,GAAG,CAAC,WAAW,CAAC;AACvC,MAAMC,sBAAsB,GAAG,CAAC,eAAe,CAAC;AAChD,MAAMC,gBAAgB,GAAG,CAAC,OAAO,CAAC;;AAElC;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAACC,OAA2B,EAAE;EACtD,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIT,eAAe,CAACU,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AACpF;;AAEA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACH,OAA2B,EAAE;EAC3D,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIP,qBAAqB,CAACQ,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AAC1F;;AAEA;AACA;AACA;AACA;AACO,SAASG,WAAWA,CAACJ,OAA2B,EAAE;EACvD,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIN,gBAAgB,CAACO,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAACL,OAA2B,EAAE;EACxD,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIL,iBAAiB,CAACM,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AACtF;;AAEA;AACA;AACA;AACA;AACO,SAASK,gBAAgBA,CAACN,OAA2B,EAAE;EAC5D,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIJ,sBAAsB,CAACK,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AAC3F;;AAEA;AACA;AACA;AACA;AACO,SAASM,WAAWA,CAACP,OAA2B,EAAE;EACvD,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAIH,gBAAgB,CAACI,QAAQ,CAACF,OAAO,CAACC,IAAI,CAAC;AACrF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-accessibility-state.js","names":["_accessibility","require","matchAccessibilityState","node","matcher","busy","undefined","computeAriaBusy","checked","computeAriaChecked","disabled","computeAriaDisabled","expanded","computeAriaExpanded","selected","computeAriaSelected"],"sources":["../../../src/helpers/matchers/match-accessibility-state.ts"],"sourcesContent":["import type { HostElement } from '
|
|
1
|
+
{"version":3,"file":"match-accessibility-state.js","names":["_accessibility","require","matchAccessibilityState","node","matcher","busy","undefined","computeAriaBusy","checked","computeAriaChecked","disabled","computeAriaDisabled","expanded","computeAriaExpanded","selected","computeAriaSelected"],"sources":["../../../src/helpers/matchers/match-accessibility-state.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport {\n computeAriaBusy,\n computeAriaChecked,\n computeAriaDisabled,\n computeAriaExpanded,\n computeAriaSelected,\n} from '../accessibility';\n\n// This type is the same as AccessibilityState from `react-native` package\n// It is re-declared here due to issues with migration from `@types/react-native` to\n// built in `react-native` types.\n// See: https://github.com/callstack/react-native-testing-library/issues/1351\nexport interface AccessibilityStateMatcher {\n disabled?: boolean;\n selected?: boolean;\n checked?: boolean | 'mixed';\n busy?: boolean;\n expanded?: boolean;\n}\n\nexport function matchAccessibilityState(node: HostElement, matcher: AccessibilityStateMatcher) {\n if (matcher.busy !== undefined && matcher.busy !== computeAriaBusy(node)) {\n return false;\n }\n if (matcher.checked !== undefined && matcher.checked !== computeAriaChecked(node)) {\n return false;\n }\n if (matcher.disabled !== undefined && matcher.disabled !== computeAriaDisabled(node)) {\n return false;\n }\n if (matcher.expanded !== undefined && matcher.expanded !== computeAriaExpanded(node)) {\n return false;\n }\n if (matcher.selected !== undefined && matcher.selected !== computeAriaSelected(node)) {\n return false;\n }\n\n return true;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AAQA;AACA;AACA;AACA;;AASO,SAASC,uBAAuBA,CAACC,IAAiB,EAAEC,OAAkC,EAAE;EAC7F,IAAIA,OAAO,CAACC,IAAI,KAAKC,SAAS,IAAIF,OAAO,CAACC,IAAI,KAAK,IAAAE,8BAAe,EAACJ,IAAI,CAAC,EAAE;IACxE,OAAO,KAAK;EACd;EACA,IAAIC,OAAO,CAACI,OAAO,KAAKF,SAAS,IAAIF,OAAO,CAACI,OAAO,KAAK,IAAAC,iCAAkB,EAACN,IAAI,CAAC,EAAE;IACjF,OAAO,KAAK;EACd;EACA,IAAIC,OAAO,CAACM,QAAQ,KAAKJ,SAAS,IAAIF,OAAO,CAACM,QAAQ,KAAK,IAAAC,kCAAmB,EAACR,IAAI,CAAC,EAAE;IACpF,OAAO,KAAK;EACd;EACA,IAAIC,OAAO,CAACQ,QAAQ,KAAKN,SAAS,IAAIF,OAAO,CAACQ,QAAQ,KAAK,IAAAC,kCAAmB,EAACV,IAAI,CAAC,EAAE;IACpF,OAAO,KAAK;EACd;EACA,IAAIC,OAAO,CAACU,QAAQ,KAAKR,SAAS,IAAIF,OAAO,CAACU,QAAQ,KAAK,IAAAC,kCAAmB,EAACZ,IAAI,CAAC,EAAE;IACpF,OAAO,KAAK;EACd;EAEA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-accessibility-value.js","names":["_accessibility","require","_matchStringProp","matchAccessibilityValue","node","matcher","value","computeAriaValue","min","undefined","max","now","text","matchStringProp"],"sources":["../../../src/helpers/matchers/match-accessibility-value.ts"],"sourcesContent":["import type { HostElement } from '
|
|
1
|
+
{"version":3,"file":"match-accessibility-value.js","names":["_accessibility","require","_matchStringProp","matchAccessibilityValue","node","matcher","value","computeAriaValue","min","undefined","max","now","text","matchStringProp"],"sources":["../../../src/helpers/matchers/match-accessibility-value.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport type { TextMatch } from '../../matches';\nimport { computeAriaValue } from '../accessibility';\nimport { matchStringProp } from './match-string-prop';\n\nexport interface AccessibilityValueMatcher {\n min?: number;\n max?: number;\n now?: number;\n text?: TextMatch;\n}\n\nexport function matchAccessibilityValue(\n node: HostElement,\n matcher: AccessibilityValueMatcher,\n): boolean {\n const value = computeAriaValue(node);\n return (\n (matcher.min === undefined || matcher.min === value?.min) &&\n (matcher.max === undefined || matcher.max === value?.max) &&\n (matcher.now === undefined || matcher.now === value?.now) &&\n (matcher.text === undefined || matchStringProp(value?.text, matcher.text))\n );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AASO,SAASE,uBAAuBA,CACrCC,IAAiB,EACjBC,OAAkC,EACzB;EACT,MAAMC,KAAK,GAAG,IAAAC,+BAAgB,EAACH,IAAI,CAAC;EACpC,OACE,CAACC,OAAO,CAACG,GAAG,KAAKC,SAAS,IAAIJ,OAAO,CAACG,GAAG,KAAKF,KAAK,EAAEE,GAAG,MACvDH,OAAO,CAACK,GAAG,KAAKD,SAAS,IAAIJ,OAAO,CAACK,GAAG,KAAKJ,KAAK,EAAEI,GAAG,CAAC,KACxDL,OAAO,CAACM,GAAG,KAAKF,SAAS,IAAIJ,OAAO,CAACM,GAAG,KAAKL,KAAK,EAAEK,GAAG,CAAC,KACxDN,OAAO,CAACO,IAAI,KAAKH,SAAS,IAAI,IAAAI,gCAAe,EAACP,KAAK,EAAEM,IAAI,EAAEP,OAAO,CAACO,IAAI,CAAC,CAAC;AAE9E","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { HostElement } from '
|
|
1
|
+
import type { HostElement } from 'test-renderer';
|
|
2
2
|
import type { TextMatch, TextMatchOptions } from '../../matches';
|
|
3
3
|
export declare function matchAccessibilityLabel(element: HostElement, expectedLabel: TextMatch, options?: TextMatchOptions): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-label-text.js","names":["_matches","require","_accessibility","matchAccessibilityLabel","element","expectedLabel","options","matches","computeAriaLabel","normalizer","exact"],"sources":["../../../src/helpers/matchers/match-label-text.ts"],"sourcesContent":["import type { HostElement } from '
|
|
1
|
+
{"version":3,"file":"match-label-text.js","names":["_matches","require","_accessibility","matchAccessibilityLabel","element","expectedLabel","options","matches","computeAriaLabel","normalizer","exact"],"sources":["../../../src/helpers/matchers/match-label-text.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport type { TextMatch, TextMatchOptions } from '../../matches';\nimport { matches } from '../../matches';\nimport { computeAriaLabel } from '../accessibility';\n\nexport function matchAccessibilityLabel(\n element: HostElement,\n expectedLabel: TextMatch,\n options?: TextMatchOptions,\n) {\n return matches(expectedLabel, computeAriaLabel(element), options?.normalizer, options?.exact);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAEO,SAASE,uBAAuBA,CACrCC,OAAoB,EACpBC,aAAwB,EACxBC,OAA0B,EAC1B;EACA,OAAO,IAAAC,gBAAO,EAACF,aAAa,EAAE,IAAAG,+BAAgB,EAACJ,OAAO,CAAC,EAAEE,OAAO,EAAEG,UAAU,EAAEH,OAAO,EAAEI,KAAK,CAAC;AAC/F","ignoreList":[]}
|