@testing-library/react-native 12.8.1 → 13.0.0-alpha.1
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 +1 -5
- package/build/act.d.ts +2 -1
- package/build/act.js +14 -10
- package/build/act.js.map +1 -1
- package/build/config.d.ts +5 -20
- package/build/config.js +1 -8
- package/build/config.js.map +1 -1
- package/build/fire-event.js +1 -1
- package/build/fire-event.js.map +1 -1
- package/build/flush-micro-tasks.d.ts +0 -18
- package/build/flush-micro-tasks.js +0 -25
- package/build/flush-micro-tasks.js.map +1 -1
- package/build/helpers/accessibility.d.ts +1 -2
- package/build/helpers/accessibility.js +13 -21
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +2 -2
- package/build/helpers/component-tree.js +0 -3
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/{debug-deep.d.ts → debug.d.ts} +1 -1
- package/build/helpers/{debug-deep.js → debug.js} +3 -3
- package/build/helpers/debug.js.map +1 -0
- package/build/helpers/host-component-names.d.ts +6 -9
- package/build/helpers/host-component-names.js +12 -71
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +1 -1
- package/build/helpers/matchers/match-label-text.js +2 -13
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/wrap-async.js +10 -27
- package/build/helpers/wrap-async.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.flow.js +4 -37
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/matchers/to-be-busy.js.map +1 -1
- package/build/matchers/to-be-checked.js.map +1 -1
- package/build/matchers/to-be-disabled.js.map +1 -1
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-expanded.js.map +1 -1
- package/build/matchers/to-be-on-the-screen.js.map +1 -1
- package/build/matchers/to-be-partially-checked.js.map +1 -1
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.js.map +1 -1
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.js +4 -0
- package/build/matchers/utils.js.map +1 -1
- package/build/queries/label-text.js +1 -1
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/options.js +4 -0
- package/build/render-hook.js +1 -2
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +6 -60
- package/build/render.js +6 -13
- package/build/render.js.map +1 -1
- package/build/screen.js +0 -25
- package/build/screen.js.map +1 -1
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/within.d.ts +0 -24
- package/build/within.js +0 -4
- package/build/within.js.map +1 -1
- package/matchers.d.ts +1 -0
- package/matchers.js +2 -0
- package/package.json +22 -17
- package/typings/index.flow.js +4 -37
- package/build/helpers/debug-deep.js.map +0 -1
- package/build/helpers/debug-shallow.d.ts +0 -6
- package/build/helpers/debug-shallow.js +0 -25
- package/build/helpers/debug-shallow.js.map +0 -1
- package/build/queries/accessibility-state.d.ts +0 -19
- package/build/queries/accessibility-state.js +0 -59
- package/build/queries/accessibility-state.js.map +0 -1
- package/build/queries/accessibility-value.d.ts +0 -19
- package/build/queries/accessibility-value.js +0 -59
- package/build/queries/accessibility-value.js.map +0 -1
- package/build/shallow.d.ts +0 -8
- package/build/shallow.js +0 -24
- package/build/shallow.js.map +0 -1
- package/extend-expect.d.ts +0 -1
- package/extend-expect.js +0 -1
package/README.md
CHANGED
|
@@ -44,11 +44,7 @@ This library has a `peerDependencies` listing for `react-test-renderer`. Make su
|
|
|
44
44
|
|
|
45
45
|
### Additional Jest matchers
|
|
46
46
|
|
|
47
|
-
You can use the built-in Jest matchers by
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import '@testing-library/react-native/extend-expect';
|
|
51
|
-
```
|
|
47
|
+
You can use the built-in Jest matchers automatically by having any import from `@testing-library/react-native` in your test.
|
|
52
48
|
|
|
53
49
|
## Example
|
|
54
50
|
|
package/build/act.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { act as reactTestRendererAct } from 'react-test-renderer';
|
|
2
|
-
type ReactAct = typeof reactTestRendererAct;
|
|
3
|
+
type ReactAct = 0 extends 1 & typeof React.act ? typeof reactTestRendererAct : typeof React.act;
|
|
3
4
|
declare global {
|
|
4
5
|
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
5
6
|
}
|
package/build/act.js
CHANGED
|
@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
8
8
|
exports.setReactActEnvironment = setIsReactActEnvironment;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
10
|
var _reactTestRenderer = require("react-test-renderer");
|
|
10
|
-
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
13
|
// This file and the act() implementation is sourced from react-testing-library
|
|
12
|
-
// https://github.com/testing-library/react-testing-library/blob/
|
|
14
|
+
// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/types/index.d.ts
|
|
15
|
+
|
|
16
|
+
const reactAct = typeof React.act === 'function' ? React.act : _reactTestRenderer.act;
|
|
13
17
|
|
|
14
18
|
// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT
|
|
15
19
|
|
|
@@ -23,17 +27,13 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
23
27
|
return callback => {
|
|
24
28
|
const previousActEnvironment = getIsReactActEnvironment();
|
|
25
29
|
setIsReactActEnvironment(true);
|
|
26
|
-
|
|
27
|
-
// this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do
|
|
28
30
|
try {
|
|
29
31
|
// The return value of `act` is always a thenable.
|
|
30
32
|
let callbackNeedsToBeAwaited = false;
|
|
31
33
|
const actResult = actImplementation(() => {
|
|
32
34
|
const result = callback();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
36
|
-
typeof result.then === 'function') {
|
|
35
|
+
// @ts-expect-error TS is too strict here
|
|
36
|
+
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
|
|
37
37
|
callbackNeedsToBeAwaited = true;
|
|
38
38
|
}
|
|
39
39
|
return result;
|
|
@@ -42,14 +42,16 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
42
42
|
const thenable = actResult;
|
|
43
43
|
return {
|
|
44
44
|
then: (resolve, reject) => {
|
|
45
|
-
// eslint-disable-next-line
|
|
45
|
+
// eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
|
|
46
46
|
thenable.then(
|
|
47
47
|
// eslint-disable-next-line promise/always-return
|
|
48
48
|
returnValue => {
|
|
49
49
|
setIsReactActEnvironment(previousActEnvironment);
|
|
50
|
+
// @ts-expect-error
|
|
50
51
|
resolve(returnValue);
|
|
51
52
|
}, error => {
|
|
52
53
|
setIsReactActEnvironment(previousActEnvironment);
|
|
54
|
+
// @ts-expect-error
|
|
53
55
|
reject(error);
|
|
54
56
|
});
|
|
55
57
|
}
|
|
@@ -66,6 +68,8 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
66
68
|
}
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
const act = withGlobalActEnvironment(reactAct);
|
|
70
74
|
var _default = exports.default = act;
|
|
71
75
|
//# sourceMappingURL=act.js.map
|
package/build/act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.js","names":["
|
|
1
|
+
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","_reactTestRenderer","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","reactAct","act","reactTestRendererAct","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","_default","exports"],"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';\nimport { act as reactTestRendererAct } from 'react-test-renderer';\n\nconst reactAct = typeof React.act === 'function' ? React.act : reactTestRendererAct;\ntype ReactAct = 0 extends 1 & typeof React.act ? typeof reactTestRendererAct : 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 // @ts-expect-error\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\n // @ts-expect-error\n reject(error);\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\n// @ts-expect-error\nconst act = withGlobalActEnvironment(reactAct) as ReactAct;\n\nexport default act;\nexport { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAAkE,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,I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CAAC,CAAC;IACzDJ,wBAAwB,CAAC,IAAI,CAAC;IAE9B,IAAI;MACF;MACA,IAAIS,wBAAwB,GAAG,KAAK;MACpC,MAAMC,SAAS,GAAGJ,iBAAiB,CAAC,MAAM;QACxC,MAAMK,MAAM,GAAGJ,QAAQ,CAAC,CAAC;QACzB;QACA,IAAII,MAAM,KAAK,IAAI,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,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;cAChD;cACAM,OAAO,CAACE,WAAW,CAAC;YACtB,CAAC,EACAC,KAAK,IAAK;cACTjB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChD;cACAO,MAAM,CAACE,KAAK,CAAC;YACf,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;AACA,MAAMnB,GAAG,GAAGO,wBAAwB,CAACR,QAAQ,CAAa;AAAC,IAAAqB,QAAA,GAAAC,OAAA,CAAApC,OAAA,GAE5Ce,GAAG","ignoreList":[]}
|
package/build/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DebugOptions } from './helpers/debug
|
|
1
|
+
import { DebugOptions } from './helpers/debug';
|
|
2
2
|
/**
|
|
3
3
|
* Global configuration options for React Native Testing Library.
|
|
4
4
|
*/
|
|
@@ -10,8 +10,8 @@ export type Config = {
|
|
|
10
10
|
/** Default options for `debug` helper. */
|
|
11
11
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
12
12
|
/**
|
|
13
|
-
* Set to `
|
|
14
|
-
* Otherwise `render` will default to
|
|
13
|
+
* Set to `false` to disable concurrent rendering.
|
|
14
|
+
* Otherwise `render` will default to concurrent rendering.
|
|
15
15
|
*/
|
|
16
16
|
concurrentRoot: boolean;
|
|
17
17
|
};
|
|
@@ -19,23 +19,10 @@ export type ConfigAliasOptions = {
|
|
|
19
19
|
/** RTL-compatibility alias to `defaultIncludeHiddenElements` */
|
|
20
20
|
defaultHidden: boolean;
|
|
21
21
|
};
|
|
22
|
-
export type HostComponentNames = {
|
|
23
|
-
text: string;
|
|
24
|
-
textInput: string;
|
|
25
|
-
image: string;
|
|
26
|
-
switch: string;
|
|
27
|
-
scrollView: string;
|
|
28
|
-
modal: string;
|
|
29
|
-
};
|
|
30
|
-
export type InternalConfig = Config & {
|
|
31
|
-
/** Names for key React Native host components. */
|
|
32
|
-
hostComponentNames?: HostComponentNames;
|
|
33
|
-
};
|
|
34
22
|
/**
|
|
35
23
|
* Configure global options for React Native Testing Library.
|
|
36
24
|
*/
|
|
37
25
|
export declare function configure(options: Partial<Config & ConfigAliasOptions>): void;
|
|
38
|
-
export declare function configureInternal(option: Partial<InternalConfig>): void;
|
|
39
26
|
export declare function resetToDefaults(): void;
|
|
40
27
|
export declare function getConfig(): {
|
|
41
28
|
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
|
|
@@ -45,10 +32,8 @@ export declare function getConfig(): {
|
|
|
45
32
|
/** Default options for `debug` helper. */
|
|
46
33
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
47
34
|
/**
|
|
48
|
-
* Set to `
|
|
49
|
-
* Otherwise `render` will default to
|
|
35
|
+
* Set to `false` to disable concurrent rendering.
|
|
36
|
+
* Otherwise `render` will default to concurrent rendering.
|
|
50
37
|
*/
|
|
51
38
|
concurrentRoot: boolean;
|
|
52
|
-
/** Names for key React Native host components. */
|
|
53
|
-
hostComponentNames?: HostComponentNames;
|
|
54
39
|
};
|
package/build/config.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.configure = configure;
|
|
7
|
-
exports.configureInternal = configureInternal;
|
|
8
7
|
exports.getConfig = getConfig;
|
|
9
8
|
exports.resetToDefaults = resetToDefaults;
|
|
10
9
|
/**
|
|
@@ -14,7 +13,7 @@ exports.resetToDefaults = resetToDefaults;
|
|
|
14
13
|
const defaultConfig = {
|
|
15
14
|
asyncUtilTimeout: 1000,
|
|
16
15
|
defaultIncludeHiddenElements: false,
|
|
17
|
-
concurrentRoot:
|
|
16
|
+
concurrentRoot: true
|
|
18
17
|
};
|
|
19
18
|
let config = {
|
|
20
19
|
...defaultConfig
|
|
@@ -35,12 +34,6 @@ function configure(options) {
|
|
|
35
34
|
defaultIncludeHiddenElements
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
function configureInternal(option) {
|
|
39
|
-
config = {
|
|
40
|
-
...config,
|
|
41
|
-
...option
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
37
|
function resetToDefaults() {
|
|
45
38
|
config = {
|
|
46
39
|
...defaultConfig
|
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","concurrentRoot","config","configure","options","defaultHidden","restOptions","
|
|
1
|
+
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","concurrentRoot","config","configure","options","defaultHidden","restOptions","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debug';\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 /**\n * Set to `false` to disable concurrent rendering.\n * Otherwise `render` will default to concurrent rendering.\n */\n concurrentRoot: boolean;\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 concurrentRoot: true,\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 { defaultHidden, ...restOptions } = options;\n\n const defaultIncludeHiddenElements =\n restOptions.defaultIncludeHiddenElements ??\n defaultHidden ??\n config.defaultIncludeHiddenElements;\n\n config = {\n ...config,\n ...restOptions,\n defaultIncludeHiddenElements,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AAEA;AACA;AACA;;AAwBA,MAAMA,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE,KAAK;EACnCC,cAAc,EAAE;AAClB,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGJ;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASK,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMJ,4BAA4B,GAChCM,WAAW,CAACN,4BAA4B,IACxCK,aAAa,IACbH,MAAM,CAACF,4BAA4B;EAErCE,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdN;EACF,CAAC;AACH;AAEO,SAASO,eAAeA,CAAA,EAAG;EAChCL,MAAM,GAAG;IAAE,GAAGJ;EAAc,CAAC;AAC/B;AAEO,SAASU,SAASA,CAAA,EAAG;EAC1B,OAAON,MAAM;AACf","ignoreList":[]}
|
package/build/fire-event.js
CHANGED
|
@@ -36,7 +36,7 @@ const eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);
|
|
|
36
36
|
*/
|
|
37
37
|
const textInputEventsIgnoringEditableProp = new Set(['contentSizeChange', 'onContentSizeChange', 'layout', 'onLayout', 'scroll', 'onScroll']);
|
|
38
38
|
function isEventEnabled(element, eventName, nearestTouchResponder) {
|
|
39
|
-
if ((0, _hostComponentNames.isHostTextInput)(nearestTouchResponder)) {
|
|
39
|
+
if (nearestTouchResponder != null && (0, _hostComponentNames.isHostTextInput)(nearestTouchResponder)) {
|
|
40
40
|
return (0, _textInput.isTextInputEditable)(nearestTouchResponder) || textInputEventsIgnoringEditableProp.has(eventName);
|
|
41
41
|
}
|
|
42
42
|
if (eventsAffectedByPointerEventsProp.has(eventName) && !(0, _pointerEvents.isPointerEventEnabled)(element)) {
|
package/build/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\nimport { Point, StringWithAutocomplete } from './types';\nimport { nativeState } from './native-state';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\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: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(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: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\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: ReactTestInstance, 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: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: ReactTestInstance, eventName: string, value: unknown) {\n if (\n eventName === 'changeText' &&\n typeof value === 'string' &&\n isHostTextInput(element) &&\n isTextInputEditable(element)\n ) {\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":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA6C,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAItC,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,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,GA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;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","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\nimport { Point, StringWithAutocomplete } from './types';\nimport { nativeState } from './native-state';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\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: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n) {\n if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(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: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\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: ReactTestInstance, 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: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: ReactTestInstance, eventName: string, value: unknown) {\n if (\n eventName === 'changeText' &&\n typeof value === 'string' &&\n isHostTextInput(element) &&\n isTextInputEditable(element)\n ) {\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":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA6C,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAItC,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,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,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AAI,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,19 +1 @@
|
|
|
1
1
|
export declare function flushMicroTasks(): Promise<unknown>;
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated To be removed in the next major release.
|
|
4
|
-
*/
|
|
5
|
-
type Thenable<T> = {
|
|
6
|
-
then: (callback: () => T) => unknown;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* This legacy implementation of `flushMicroTasks` is used for compatibility with
|
|
10
|
-
* older versions of React Native (pre 0.71) which uses Promise polyfil.
|
|
11
|
-
*
|
|
12
|
-
* For users with older version of React Native there is a workaround of using our own
|
|
13
|
-
* Jest preset instead the `react-native` one, but requiring such change would be a
|
|
14
|
-
* breaking change for existing users.
|
|
15
|
-
*
|
|
16
|
-
* @deprecated To be removed in the next major release.
|
|
17
|
-
*/
|
|
18
|
-
export declare function flushMicroTasksLegacy(): Thenable<void>;
|
|
19
|
-
export {};
|
|
@@ -4,33 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.flushMicroTasks = flushMicroTasks;
|
|
7
|
-
exports.flushMicroTasksLegacy = flushMicroTasksLegacy;
|
|
8
7
|
var _timers = require("./helpers/timers");
|
|
9
8
|
function flushMicroTasks() {
|
|
10
9
|
return new Promise(resolve => (0, _timers.setImmediate)(resolve));
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated To be removed in the next major release.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This legacy implementation of `flushMicroTasks` is used for compatibility with
|
|
19
|
-
* older versions of React Native (pre 0.71) which uses Promise polyfil.
|
|
20
|
-
*
|
|
21
|
-
* For users with older version of React Native there is a workaround of using our own
|
|
22
|
-
* Jest preset instead the `react-native` one, but requiring such change would be a
|
|
23
|
-
* breaking change for existing users.
|
|
24
|
-
*
|
|
25
|
-
* @deprecated To be removed in the next major release.
|
|
26
|
-
*/
|
|
27
|
-
function flushMicroTasksLegacy() {
|
|
28
|
-
return {
|
|
29
|
-
// using "thenable" instead of a Promise, because otherwise it breaks when
|
|
30
|
-
// using "modern" fake timers
|
|
31
|
-
then(resolve) {
|
|
32
|
-
(0, _timers.setImmediate)(resolve);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
11
|
//# sourceMappingURL=flush-micro-tasks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flush-micro-tasks.js","names":["_timers","require","flushMicroTasks","Promise","resolve","setImmediate"
|
|
1
|
+
{"version":3,"file":"flush-micro-tasks.js","names":["_timers","require","flushMicroTasks","Promise","resolve","setImmediate"],"sources":["../src/flush-micro-tasks.ts"],"sourcesContent":["import { setImmediate } from './helpers/timers';\n\nexport function flushMicroTasks() {\n return new Promise((resolve) => setImmediate(resolve));\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEO,SAASC,eAAeA,CAAA,EAAG;EAChC,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAK,IAAAC,oBAAY,EAACD,OAAO,CAAC,CAAC;AACxD","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';
|
|
2
|
-
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
3
3
|
type IsInaccessibleOptions = {
|
|
4
4
|
cache?: WeakMap<ReactTestInstance, boolean>;
|
|
5
5
|
};
|
|
@@ -33,7 +33,6 @@ export declare function getRole(element: ReactTestInstance): Role | Accessibilit
|
|
|
33
33
|
export declare function normalizeRole(role: string): Role | AccessibilityRole;
|
|
34
34
|
export declare function computeAriaModal(element: ReactTestInstance): boolean | undefined;
|
|
35
35
|
export declare function computeAriaLabel(element: ReactTestInstance): string | undefined;
|
|
36
|
-
export declare function computeAriaLabelledBy(element: ReactTestInstance): string | undefined;
|
|
37
36
|
export declare function computeAriaBusy({ props }: ReactTestInstance): boolean;
|
|
38
37
|
export declare function computeAriaChecked(element: ReactTestInstance): AccessibilityState['checked'];
|
|
39
38
|
export declare function computeAriaDisabled(element: ReactTestInstance): boolean;
|
|
@@ -10,7 +10,6 @@ exports.computeAriaChecked = computeAriaChecked;
|
|
|
10
10
|
exports.computeAriaDisabled = computeAriaDisabled;
|
|
11
11
|
exports.computeAriaExpanded = computeAriaExpanded;
|
|
12
12
|
exports.computeAriaLabel = computeAriaLabel;
|
|
13
|
-
exports.computeAriaLabelledBy = computeAriaLabelledBy;
|
|
14
13
|
exports.computeAriaModal = computeAriaModal;
|
|
15
14
|
exports.computeAriaSelected = computeAriaSelected;
|
|
16
15
|
exports.computeAriaValue = computeAriaValue;
|
|
@@ -22,6 +21,7 @@ exports.normalizeRole = normalizeRole;
|
|
|
22
21
|
exports.rolesSupportingCheckedState = void 0;
|
|
23
22
|
var _reactNative = require("react-native");
|
|
24
23
|
var _componentTree = require("./component-tree");
|
|
24
|
+
var _findAll = require("./find-all");
|
|
25
25
|
var _hostComponentNames = require("./host-component-names");
|
|
26
26
|
var _textContent = require("./text-content");
|
|
27
27
|
var _textInput = require("./text-input");
|
|
@@ -97,8 +97,7 @@ function isAccessibilityElement(element) {
|
|
|
97
97
|
if (element.props.accessible !== undefined) {
|
|
98
98
|
return element.props.accessible;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
return element?.type === hostComponentNames?.text || element?.type === hostComponentNames?.textInput || element?.type === hostComponentNames?.switch;
|
|
100
|
+
return (0, _hostComponentNames.isHostText)(element) || (0, _hostComponentNames.isHostTextInput)(element) || (0, _hostComponentNames.isHostSwitch)(element);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
/**
|
|
@@ -146,6 +145,16 @@ function computeAriaModal(element) {
|
|
|
146
145
|
return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;
|
|
147
146
|
}
|
|
148
147
|
function computeAriaLabel(element) {
|
|
148
|
+
const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
|
|
149
|
+
if (labelElementId) {
|
|
150
|
+
const rootElement = (0, _componentTree.getUnsafeRootElement)(element);
|
|
151
|
+
const labelElement = (0, _findAll.findAll)(rootElement, node => (0, _componentTree.isHostElement)(node) && node.props.nativeID === labelElementId, {
|
|
152
|
+
includeHiddenElements: true
|
|
153
|
+
});
|
|
154
|
+
if (labelElement.length > 0) {
|
|
155
|
+
return (0, _textContent.getTextContent)(labelElement[0]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
149
158
|
const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;
|
|
150
159
|
if (explicitLabel) {
|
|
151
160
|
return explicitLabel;
|
|
@@ -157,9 +166,6 @@ function computeAriaLabel(element) {
|
|
|
157
166
|
}
|
|
158
167
|
return undefined;
|
|
159
168
|
}
|
|
160
|
-
function computeAriaLabelledBy(element) {
|
|
161
|
-
return element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
|
|
162
|
-
}
|
|
163
169
|
|
|
164
170
|
// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state
|
|
165
171
|
function computeAriaBusy({
|
|
@@ -223,21 +229,7 @@ function computeAriaValue(element) {
|
|
|
223
229
|
};
|
|
224
230
|
}
|
|
225
231
|
function computeAccessibleName(element) {
|
|
226
|
-
|
|
227
|
-
if (label) {
|
|
228
|
-
return label;
|
|
229
|
-
}
|
|
230
|
-
const labelElementId = computeAriaLabelledBy(element);
|
|
231
|
-
if (labelElementId) {
|
|
232
|
-
const rootElement = (0, _componentTree.getUnsafeRootElement)(element);
|
|
233
|
-
const labelElement = rootElement?.findByProps({
|
|
234
|
-
nativeID: labelElementId
|
|
235
|
-
});
|
|
236
|
-
if (labelElement) {
|
|
237
|
-
return (0, _textContent.getTextContent)(labelElement);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return (0, _textContent.getTextContent)(element);
|
|
232
|
+
return computeAriaLabel(element) ?? (0, _textContent.getTextContent)(element);
|
|
241
233
|
}
|
|
242
234
|
const rolesSupportingCheckedState = exports.rolesSupportingCheckedState = {
|
|
243
235
|
checkbox: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_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","hostComponentNames","getHostComponentNames","type","text","textInput","switch","getRole","explicitRole","role","accessibilityRole","normalizeRole","isHostText","accessibilityViewIsModal","computeAriaLabel","explicitLabel","accessibilityLabel","computeAriaLabelledBy","accessibilityLabelledBy","computeAriaBusy","accessibilityState","busy","computeAriaChecked","isHostSwitch","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isHostTextInput","isTextInputEditable","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","computeAccessibleName","label","labelElementId","rootElement","getUnsafeRootElement","labelElement","findByProps","nativeID","getTextContent","checkbox","radio"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import {\n AccessibilityRole,\n AccessibilityState,\n AccessibilityValue,\n Role,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings, getUnsafeRootElement } from './component-tree';\nimport {\n getHostComponentNames,\n isHostImage,\n isHostSwitch,\n isHostText,\n isHostTextInput,\n} from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isTextInputEditable } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, 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: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | 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: ReactTestInstance): 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: ReactTestInstance | 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 const hostComponentNames = getHostComponentNames();\n return (\n element?.type === hostComponentNames?.text ||\n element?.type === hostComponentNames?.textInput ||\n element?.type === hostComponentNames?.switch\n );\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: ReactTestInstance): 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: ReactTestInstance): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: ReactTestInstance): string | undefined {\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\nexport function computeAriaLabelledBy(element: ReactTestInstance): string | undefined {\n return element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: ReactTestInstance): 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: ReactTestInstance): 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: ReactTestInstance): boolean {\n if (isHostTextInput(element) && !isTextInputEditable(element)) {\n return true;\n }\n\n const { props } = element;\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 }: ReactTestInstance): 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 }: ReactTestInstance): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: ReactTestInstance): 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: ReactTestInstance): string | undefined {\n const label = computeAriaLabel(element);\n if (label) {\n return label;\n }\n\n const labelElementId = computeAriaLabelledBy(element);\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = rootElement?.findByProps({ nativeID: labelElementId });\n if (labelElement) {\n return getTextContent(labelElement);\n }\n }\n\n return 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":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAOA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAMO,MAAMK,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,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,C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F,WAAW,EAAEG,WAAW,CAAC;MAAEC,QAAQ,EAAEL;IAAe,CAAC,CAAC;IAC3E,IAAIG,YAAY,EAAE;MAChB,OAAO,IAAAG,2BAAc,EAACH,YAAY,CAAC;IACrC;EACF;EAEA,OAAO,IAAAG,2BAAc,EAAC9E,OAAO,CAAC;AAChC;AAIO,MAAMmD,2BAA2C,GAAAtD,OAAA,CAAAsD,2BAAA,GAAG;EACzD4B,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXhD,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","rootElement","getUnsafeRootElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isTextInputEditable","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 {\n AccessibilityRole,\n AccessibilityState,\n AccessibilityValue,\n Role,\n StyleSheet,\n} from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings, getUnsafeRootElement, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isTextInputEditable } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, 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: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | 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: ReactTestInstance): 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: ReactTestInstance | 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: ReactTestInstance): 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: ReactTestInstance): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: ReactTestInstance): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = findAll(\n rootElement,\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 }: ReactTestInstance): 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: ReactTestInstance): 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: ReactTestInstance): boolean {\n if (isHostTextInput(element) && !isTextInputEditable(element)) {\n return true;\n }\n\n const { props } = element;\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 }: ReactTestInstance): 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 }: ReactTestInstance): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: ReactTestInstance): 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: ReactTestInstance): 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":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,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,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,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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AAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export type HostTestInstance = ReactTestInstance & {
|
|
|
10
10
|
* @param element The element to check.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isHostElement(element?: ReactTestInstance | null): element is HostTestInstance;
|
|
13
|
-
export declare function isElementMounted(element: ReactTestInstance
|
|
13
|
+
export declare function isElementMounted(element: ReactTestInstance): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Returns first host ancestor for given element.
|
|
16
16
|
* @param element The element start traversing from.
|
|
@@ -40,4 +40,4 @@ export declare function getHostSiblings(element: ReactTestInstance | null): Host
|
|
|
40
40
|
* @param element The element start traversing from.
|
|
41
41
|
* @returns The root element of the tree (host or composite).
|
|
42
42
|
*/
|
|
43
|
-
export declare function getUnsafeRootElement(element: ReactTestInstance
|
|
43
|
+
export declare function getUnsafeRootElement(element: ReactTestInstance): ReactTestInstance;
|
|
@@ -94,9 +94,6 @@ function getHostSiblings(element) {
|
|
|
94
94
|
* @returns The root element of the tree (host or composite).
|
|
95
95
|
*/
|
|
96
96
|
function getUnsafeRootElement(element) {
|
|
97
|
-
if (element == null) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
97
|
let current = element;
|
|
101
98
|
while (current.parent) {
|
|
102
99
|
current = current.parent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-tree.js","names":["_screen","require","isHostElement","element","type","isElementMounted","getUnsafeRootElement","screen","UNSAFE_root","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { screen } from '../screen';\n/**\n * ReactTestInstance referring to host element.\n */\nexport type HostTestInstance = ReactTestInstance & { type: string };\n\n/**\n * Checks if the given element is a host element.\n * @param element The element to check.\n */\nexport function isHostElement(element?: ReactTestInstance | null): element is HostTestInstance {\n return typeof element?.type === 'string';\n}\n\nexport function isElementMounted(element: ReactTestInstance
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["_screen","require","isHostElement","element","type","isElementMounted","getUnsafeRootElement","screen","UNSAFE_root","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { screen } from '../screen';\n/**\n * ReactTestInstance referring to host element.\n */\nexport type HostTestInstance = ReactTestInstance & { type: string };\n\n/**\n * Checks if the given element is a host element.\n * @param element The element to check.\n */\nexport function isHostElement(element?: ReactTestInstance | null): element is HostTestInstance {\n return typeof element?.type === 'string';\n}\n\nexport function isElementMounted(element: ReactTestInstance) {\n return getUnsafeRootElement(element) === screen.UNSAFE_root;\n}\n\n/**\n * Returns first host ancestor for given element.\n * @param element The element start traversing from.\n */\nexport function getHostParent(element: ReactTestInstance | null): HostTestInstance | null {\n if (element == null) {\n return null;\n }\n\n let current = element.parent;\n while (current) {\n if (isHostElement(current)) {\n return current;\n }\n\n current = current.parent;\n }\n\n return null;\n}\n\n/**\n * Returns host children for given element.\n * @param element The element start traversing from.\n */\nexport function getHostChildren(element: ReactTestInstance | null): HostTestInstance[] {\n if (element == null) {\n return [];\n }\n\n const hostChildren: HostTestInstance[] = [];\n\n element.children.forEach((child) => {\n if (typeof child !== 'object') {\n return;\n }\n\n if (isHostElement(child)) {\n hostChildren.push(child);\n } else {\n hostChildren.push(...getHostChildren(child));\n }\n });\n\n return hostChildren;\n}\n\n/**\n * Return the array of host elements that represent the passed element.\n *\n * @param element The element start traversing from.\n * @returns If the passed element is a host element, it will return an array containing only that element,\n * if the passed element is a composite element, it will return an array containing its host children (zero, one or many).\n */\nexport function getHostSelves(element: ReactTestInstance | null): HostTestInstance[] {\n return isHostElement(element) ? [element] : getHostChildren(element);\n}\n\n/**\n * Returns host siblings for given element.\n * @param element The element start traversing from.\n */\nexport function getHostSiblings(element: ReactTestInstance | null): HostTestInstance[] {\n const hostParent = getHostParent(element);\n const hostSelves = getHostSelves(element);\n return getHostChildren(hostParent).filter((sibling) => !hostSelves.includes(sibling));\n}\n\n/**\n * Returns the unsafe root element of the tree (probably composite).\n *\n * @param element The element start traversing from.\n * @returns The root element of the tree (host or composite).\n */\nexport function getUnsafeRootElement(element: ReactTestInstance) {\n let current = element;\n while (current.parent) {\n current = current.parent;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,OAAkC,EAA+B;EAC7F,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AAC1C;AAEO,SAASC,gBAAgBA,CAACF,OAA0B,EAAE;EAC3D,OAAOG,oBAAoB,CAACH,OAAO,CAAC,KAAKI,cAAM,CAACC,WAAW;AAC7D;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACN,OAAiC,EAA2B;EACxF,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIO,OAAO,GAAGP,OAAO,CAACQ,MAAM;EAC5B,OAAOD,OAAO,EAAE;IACd,IAAIR,aAAa,CAACQ,OAAO,CAAC,EAAE;MAC1B,OAAOA,OAAO;IAChB;IAEAA,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACT,OAAiC,EAAsB;EACrF,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,EAAE;EACX;EAEA,MAAMU,YAAgC,GAAG,EAAE;EAE3CV,OAAO,CAACW,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAK;IAClC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B;IACF;IAEA,IAAId,aAAa,CAACc,KAAK,CAAC,EAAE;MACxBH,YAAY,CAACI,IAAI,CAACD,KAAK,CAAC;IAC1B,CAAC,MAAM;MACLH,YAAY,CAACI,IAAI,CAAC,GAAGL,eAAe,CAACI,KAAK,CAAC,CAAC;IAC9C;EACF,CAAC,CAAC;EAEF,OAAOH,YAAY;AACrB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,aAAaA,CAACf,OAAiC,EAAsB;EACnF,OAAOD,aAAa,CAACC,OAAO,CAAC,GAAG,CAACA,OAAO,CAAC,GAAGS,eAAe,CAACT,OAAO,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACO,SAASgB,eAAeA,CAAChB,OAAiC,EAAsB;EACrF,MAAMiB,UAAU,GAAGX,aAAa,CAACN,OAAO,CAAC;EACzC,MAAMkB,UAAU,GAAGH,aAAa,CAACf,OAAO,CAAC;EACzC,OAAOS,eAAe,CAACQ,UAAU,CAAC,CAACE,MAAM,CAAEC,OAAO,IAAK,CAACF,UAAU,CAACG,QAAQ,CAACD,OAAO,CAAC,CAAC;AACvF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASjB,oBAAoBA,CAACH,OAA0B,EAAE;EAC/D,IAAIO,OAAO,GAAGP,OAAO;EACrB,OAAOO,OAAO,CAACC,MAAM,EAAE;IACrBD,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAOD,OAAO;AAChB","ignoreList":[]}
|
|
@@ -6,4 +6,4 @@ export type DebugOptions = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Log pretty-printed deep test component instance
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export declare function debug(instance: ReactTestRendererJSON | ReactTestRendererJSON[], options?: DebugOptions | string): void;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.debug = debug;
|
|
7
7
|
var _format = _interopRequireDefault(require("./format"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
/**
|
|
10
10
|
* Log pretty-printed deep test component instance
|
|
11
11
|
*/
|
|
12
|
-
function
|
|
12
|
+
function debug(instance, options) {
|
|
13
13
|
const message = typeof options === 'string' ? options : options?.message;
|
|
14
14
|
const formatOptions = typeof options === 'object' ? {
|
|
15
15
|
mapProps: options?.mapProps
|
|
@@ -22,4 +22,4 @@ function debugDeep(instance, options) {
|
|
|
22
22
|
console.log((0, _format.default)(instance, formatOptions));
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
//# sourceMappingURL=debug
|
|
25
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.js","names":["_format","_interopRequireDefault","require","e","__esModule","default","debug","instance","options","message","formatOptions","mapProps","undefined","console","log","format"],"sources":["../../src/helpers/debug.ts"],"sourcesContent":["import type { ReactTestRendererJSON } from 'react-test-renderer';\nimport format, { FormatOptions } from './format';\n\nexport type DebugOptions = {\n message?: string;\n} & FormatOptions;\n\n/**\n * Log pretty-printed deep test component instance\n */\nexport function debug(\n instance: ReactTestRendererJSON | ReactTestRendererJSON[],\n options?: DebugOptions | string,\n) {\n const message = typeof options === 'string' ? options : options?.message;\n\n const formatOptions = typeof options === 'object' ? { mapProps: options?.mapProps } : undefined;\n\n if (message) {\n // eslint-disable-next-line no-console\n console.log(`${message}\\n\\n`, format(instance, formatOptions));\n } else {\n // eslint-disable-next-line no-console\n console.log(format(instance, formatOptions));\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAiD,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAMjD;AACA;AACA;AACO,SAASG,KAAKA,CACnBC,QAAyD,EACzDC,OAA+B,EAC/B;EACA,MAAMC,OAAO,GAAG,OAAOD,OAAO,KAAK,QAAQ,GAAGA,OAAO,GAAGA,OAAO,EAAEC,OAAO;EAExE,MAAMC,aAAa,GAAG,OAAOF,OAAO,KAAK,QAAQ,GAAG;IAAEG,QAAQ,EAAEH,OAAO,EAAEG;EAAS,CAAC,GAAGC,SAAS;EAE/F,IAAIH,OAAO,EAAE;IACX;IACAI,OAAO,CAACC,GAAG,CAAC,GAAGL,OAAO,MAAM,EAAE,IAAAM,eAAM,EAACR,QAAQ,EAAEG,aAAa,CAAC,CAAC;EAChE,CAAC,MAAM;IACL;IACAG,OAAO,CAACC,GAAG,CAAC,IAAAC,eAAM,EAACR,QAAQ,EAAEG,aAAa,CAAC,CAAC;EAC9C;AACF","ignoreList":[]}
|