@testing-library/react-native 14.0.0-alpha.0 → 14.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 -1
- package/build/act.js +2 -2
- package/build/act.js.map +1 -1
- package/build/event-handler.d.ts +7 -0
- package/build/event-handler.js +30 -0
- package/build/event-handler.js.map +1 -0
- package/build/fire-event.d.ts +3 -3
- package/build/fire-event.js +6 -16
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +2 -2
- 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 +3 -3
- package/build/helpers/debug.js +7 -9
- package/build/helpers/debug.js.map +1 -1
- package/build/helpers/errors.js +4 -4
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/find-all.d.ts +1 -1
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +18 -0
- package/build/helpers/format-element.js +80 -0
- package/build/helpers/format-element.js.map +1 -0
- 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/logger.d.ts +6 -0
- package/build/helpers/logger.js +37 -0
- package/build/helpers/logger.js.map +1 -0
- package/build/helpers/{format-default.d.ts → map-props.d.ts} +1 -0
- package/build/helpers/{format-default.js → map-props.js} +2 -2
- package/build/helpers/map-props.js.map +1 -0
- 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 +2 -2
- package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +2 -2
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/matchers/match-string-prop.d.ts +1 -1
- package/build/helpers/matchers/match-string-prop.js.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +2 -2
- package/build/helpers/matchers/match-text-content.js.map +1 -1
- package/build/helpers/object.d.ts +1 -1
- package/build/helpers/object.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 +1 -1
- package/build/helpers/timers.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.flow.js +28 -32
- package/build/index.js +3 -4
- package/build/index.js.map +1 -1
- package/build/matchers/extend-expect.js +2 -2
- package/build/matchers/extend-expect.js.map +1 -1
- package/build/matchers/index.d.ts +1 -1
- package/build/matchers/index.js.map +1 -1
- package/build/matchers/to-be-busy.d.ts +1 -1
- package/build/matchers/to-be-busy.js +4 -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 +4 -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 +5 -2
- 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 +6 -3
- 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 +5 -2
- 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 +4 -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 +4 -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 +4 -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 +5 -2
- 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 +4 -1
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.d.ts +2 -2
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +2 -2
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.d.ts +2 -2
- package/build/matchers/to-have-display-value.js +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 +2 -2
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +2 -2
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +4 -4
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +1 -8
- package/build/matchers/utils.js +0 -46
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +3 -3
- package/build/native-state.js +1 -1
- package/build/native-state.js.map +1 -1
- package/build/pure.d.ts +1 -1
- package/build/pure.js +2 -2
- package/build/pure.js.map +1 -1
- package/build/queries/display-value.d.ts +2 -2
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +3 -3
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +3 -3
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +1 -1
- package/build/queries/make-queries.js +4 -7
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/options.d.ts +1 -1
- package/build/queries/options.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +2 -2
- package/build/queries/placeholder-text.js +1 -1
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +5 -5
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +2 -2
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +2 -2
- package/build/queries/text.js.map +1 -1
- package/build/render-hook.d.ts +16 -6
- package/build/render-hook.js +22 -22
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +5 -68
- package/build/render.js +10 -15
- package/build/render.js.map +1 -1
- package/build/screen.d.ts +1 -1
- package/build/screen.js.map +1 -1
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/user-event/clear.d.ts +2 -2
- package/build/user-event/clear.js +2 -2
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/event-builder/base.d.ts +2 -2
- package/build/user-event/event-builder/base.js.map +1 -1
- package/build/user-event/event-builder/scroll-view.d.ts +1 -1
- package/build/user-event/event-builder/scroll-view.js.map +1 -1
- package/build/user-event/event-builder/text-input.d.ts +2 -2
- package/build/user-event/event-builder/text-input.js.map +1 -1
- package/build/user-event/index.d.ts +4 -4
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +2 -2
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/index.d.ts +1 -1
- package/build/user-event/press/index.js.map +1 -1
- package/build/user-event/press/press.d.ts +2 -2
- package/build/user-event/press/press.js +34 -42
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/index.d.ts +1 -1
- package/build/user-event/scroll/index.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +3 -3
- package/build/user-event/scroll/scroll-to.js +1 -1
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/scroll/utils.d.ts +1 -1
- package/build/user-event/scroll/utils.js.map +1 -1
- package/build/user-event/setup/setup.d.ts +4 -4
- package/build/user-event/setup/setup.js.map +1 -1
- package/build/user-event/type/type.d.ts +3 -2
- package/build/user-event/type/type.js +7 -5
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/content-size.d.ts +1 -1
- package/build/user-event/utils/content-size.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +1 -1
- package/build/user-event/utils/dispatch-event.js +2 -12
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/user-event/utils/wait.d.ts +6 -2
- package/build/user-event/utils/wait.js +1 -1
- package/build/user-event/utils/wait.js.map +1 -1
- package/build/wait-for-element-to-be-removed.js +1 -1
- package/build/wait-for-element-to-be-removed.js.map +1 -1
- package/build/wait-for.js +1 -4
- 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 +17 -13
- package/typings/index.flow.js +28 -32
- package/build/helpers/format-default.js.map +0 -1
- package/build/helpers/format.d.ts +0 -7
- package/build/helpers/format.js +0 -31
- package/build/helpers/format.js.map +0 -1
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ React Native Testing Library consists of following APIs:
|
|
|
102
102
|
|
|
103
103
|
## Migration Guides
|
|
104
104
|
|
|
105
|
-
- [Migration to
|
|
105
|
+
- [Migration to 13.0](https://callstack.github.io/react-native-testing-library/docs/migration/v13)
|
|
106
106
|
- [Migration to built-in Jest Matchers](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers)
|
|
107
107
|
|
|
108
108
|
## Troubleshooting
|
package/build/act.js
CHANGED
|
@@ -44,11 +44,11 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
44
44
|
// eslint-disable-next-line promise/always-return
|
|
45
45
|
returnValue => {
|
|
46
46
|
setIsReactActEnvironment(previousActEnvironment);
|
|
47
|
-
// @ts-expect-error
|
|
47
|
+
// @ts-expect-error too strict typing
|
|
48
48
|
resolve(returnValue);
|
|
49
49
|
}, error => {
|
|
50
50
|
setIsReactActEnvironment(previousActEnvironment);
|
|
51
|
-
// @ts-expect-error
|
|
51
|
+
// @ts-expect-error too strict typing
|
|
52
52
|
reject(error);
|
|
53
53
|
});
|
|
54
54
|
}
|
package/build/act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","act","_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';\n\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 // @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\nconst act = withGlobalActEnvironment(React.act);\n\nexport default act;\nexport { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAC,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,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAF/B;AACA;;AAKA;;
|
|
1
|
+
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","act","_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';\n\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 // eslint-disable-next-line no-var\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 too strict typing\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\n // @ts-expect-error too strict typing\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\nconst act = withGlobalActEnvironment(React.act);\n\nexport default act;\nexport { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAC,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,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,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I,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,MAAMC,GAAG,GAAGb,wBAAwB,CAAC5B,KAAK,CAACyC,GAAG,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAlC,OAAA,GAEjCgC,GAAG","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
|
+
export type EventHandlerOptions = {
|
|
3
|
+
/** Include check for event handler named without adding `on*` prefix. */
|
|
4
|
+
loose?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function getEventHandler(element: HostElement, eventName: string, options?: EventHandlerOptions): any;
|
|
7
|
+
export declare function getEventHandlerName(eventName: string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getEventHandler = getEventHandler;
|
|
7
|
+
exports.getEventHandlerName = getEventHandlerName;
|
|
8
|
+
function getEventHandler(element, eventName, options) {
|
|
9
|
+
const handlerName = getEventHandlerName(eventName);
|
|
10
|
+
if (typeof element.props[handlerName] === 'function') {
|
|
11
|
+
return element.props[handlerName];
|
|
12
|
+
}
|
|
13
|
+
if (options?.loose && typeof element.props[eventName] === 'function') {
|
|
14
|
+
return element.props[eventName];
|
|
15
|
+
}
|
|
16
|
+
if (typeof element.props[`testOnly_${handlerName}`] === 'function') {
|
|
17
|
+
return element.props[`testOnly_${handlerName}`];
|
|
18
|
+
}
|
|
19
|
+
if (options?.loose && typeof element.props[`testOnly_${eventName}`] === 'function') {
|
|
20
|
+
return element.props[`testOnly_${eventName}`];
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
function getEventHandlerName(eventName) {
|
|
25
|
+
return `on${capitalizeFirstLetter(eventName)}`;
|
|
26
|
+
}
|
|
27
|
+
function capitalizeFirstLetter(str) {
|
|
28
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=event-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-handler.js","names":["getEventHandler","element","eventName","options","handlerName","getEventHandlerName","props","loose","undefined","capitalizeFirstLetter","str","charAt","toUpperCase","slice"],"sources":["../src/event-handler.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nexport type EventHandlerOptions = {\n /** Include check for event handler named without adding `on*` prefix. */\n loose?: boolean;\n};\n\nexport function getEventHandler(\n element: HostElement,\n eventName: string,\n options?: EventHandlerOptions,\n) {\n const handlerName = getEventHandlerName(eventName);\n if (typeof element.props[handlerName] === 'function') {\n return element.props[handlerName];\n }\n\n if (options?.loose && typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n if (typeof element.props[`testOnly_${handlerName}`] === 'function') {\n return element.props[`testOnly_${handlerName}`];\n }\n\n if (options?.loose && typeof element.props[`testOnly_${eventName}`] === 'function') {\n return element.props[`testOnly_${eventName}`];\n }\n\n return undefined;\n}\n\nexport function getEventHandlerName(eventName: string) {\n return `on${capitalizeFirstLetter(eventName)}`;\n}\n\nfunction capitalizeFirstLetter(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"],"mappings":";;;;;;;AAOO,SAASA,eAAeA,CAC7BC,OAAoB,EACpBC,SAAiB,EACjBC,OAA6B,EAC7B;EACA,MAAMC,WAAW,GAAGC,mBAAmB,CAACH,SAAS,CAAC;EAClD,IAAI,OAAOD,OAAO,CAACK,KAAK,CAACF,WAAW,CAAC,KAAK,UAAU,EAAE;IACpD,OAAOH,OAAO,CAACK,KAAK,CAACF,WAAW,CAAC;EACnC;EAEA,IAAID,OAAO,EAAEI,KAAK,IAAI,OAAON,OAAO,CAACK,KAAK,CAACJ,SAAS,CAAC,KAAK,UAAU,EAAE;IACpE,OAAOD,OAAO,CAACK,KAAK,CAACJ,SAAS,CAAC;EACjC;EAEA,IAAI,OAAOD,OAAO,CAACK,KAAK,CAAC,YAAYF,WAAW,EAAE,CAAC,KAAK,UAAU,EAAE;IAClE,OAAOH,OAAO,CAACK,KAAK,CAAC,YAAYF,WAAW,EAAE,CAAC;EACjD;EAEA,IAAID,OAAO,EAAEI,KAAK,IAAI,OAAON,OAAO,CAACK,KAAK,CAAC,YAAYJ,SAAS,EAAE,CAAC,KAAK,UAAU,EAAE;IAClF,OAAOD,OAAO,CAACK,KAAK,CAAC,YAAYJ,SAAS,EAAE,CAAC;EAC/C;EAEA,OAAOM,SAAS;AAClB;AAEO,SAASH,mBAAmBA,CAACH,SAAiB,EAAE;EACrD,OAAO,KAAKO,qBAAqB,CAACP,SAAS,CAAC,EAAE;AAChD;AAEA,SAASO,qBAAqBA,CAACC,GAAW,EAAE;EAC1C,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC;AACnD","ignoreList":[]}
|
package/build/fire-event.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HostElement } from 'universal-test-renderer';
|
|
3
|
-
import { StringWithAutocomplete } from './types';
|
|
1
|
+
import type { PressableProps, ScrollViewProps, TextInputProps, TextProps, ViewProps } from 'react-native';
|
|
2
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
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;
|
|
6
6
|
type EventNameExtractor<T> = keyof {
|
package/build/fire-event.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
exports.isEventEnabled = isEventEnabled;
|
|
8
8
|
exports.isTouchResponder = isTouchResponder;
|
|
9
9
|
var _act = _interopRequireDefault(require("./act"));
|
|
10
|
+
var _eventHandler = require("./event-handler");
|
|
10
11
|
var _componentTree = require("./helpers/component-tree");
|
|
11
12
|
var _hostComponentNames = require("./helpers/host-component-names");
|
|
12
13
|
var _pointerEvents = require("./helpers/pointer-events");
|
|
@@ -52,7 +53,9 @@ function isEventEnabled(element, eventName, nearestTouchResponder) {
|
|
|
52
53
|
}
|
|
53
54
|
function findEventHandler(element, eventName, nearestTouchResponder) {
|
|
54
55
|
const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
|
|
55
|
-
const handler = getEventHandler(element, eventName
|
|
56
|
+
const handler = (0, _eventHandler.getEventHandler)(element, eventName, {
|
|
57
|
+
loose: true
|
|
58
|
+
});
|
|
56
59
|
if (handler && isEventEnabled(element, eventName, touchResponder)) {
|
|
57
60
|
return handler;
|
|
58
61
|
}
|
|
@@ -63,19 +66,6 @@ function findEventHandler(element, eventName, nearestTouchResponder) {
|
|
|
63
66
|
}
|
|
64
67
|
return findEventHandler(element.parent, eventName, touchResponder);
|
|
65
68
|
}
|
|
66
|
-
function getEventHandler(element, eventName) {
|
|
67
|
-
const eventHandlerName = getEventHandlerName(eventName);
|
|
68
|
-
if (typeof element.props[eventHandlerName] === 'function') {
|
|
69
|
-
return element.props[eventHandlerName];
|
|
70
|
-
}
|
|
71
|
-
if (typeof element.props[eventName] === 'function') {
|
|
72
|
-
return element.props[eventName];
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
function getEventHandlerName(eventName) {
|
|
77
|
-
return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
|
|
78
|
-
}
|
|
79
69
|
|
|
80
70
|
// String union type of keys of T that start with on, stripped of 'on'
|
|
81
71
|
|
|
@@ -96,7 +86,7 @@ function fireEvent(element, eventName, ...data) {
|
|
|
96
86
|
}
|
|
97
87
|
fireEvent.press = (element, ...data) => {
|
|
98
88
|
const nativeData = data.length === 1 && typeof data[0] === 'object' && data[0] !== null && 'nativeEvent' in data[0] && typeof data[0].nativeEvent === 'object' ? data[0].nativeEvent : null;
|
|
99
|
-
|
|
89
|
+
const responderGrantEvent = _eventBuilder.EventBuilder.Common.responderGrant();
|
|
100
90
|
if (nativeData) {
|
|
101
91
|
responderGrantEvent.nativeEvent = {
|
|
102
92
|
...responderGrantEvent.nativeEvent,
|
|
@@ -105,7 +95,7 @@ fireEvent.press = (element, ...data) => {
|
|
|
105
95
|
}
|
|
106
96
|
fireEvent(element, 'responderGrant', responderGrantEvent);
|
|
107
97
|
fireEvent(element, 'press', ...data);
|
|
108
|
-
|
|
98
|
+
const responderReleaseEvent = _eventBuilder.EventBuilder.Common.responderRelease();
|
|
109
99
|
if (nativeData) {
|
|
110
100
|
responderReleaseEvent.nativeEvent = {
|
|
111
101
|
...responderReleaseEvent.nativeEvent,
|
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","_eventBuilder","e","__esModule","default","isTouchResponder","element","isValidElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","nativeData","length","nativeEvent","responderGrantEvent","EventBuilder","Common","responderGrant","responderReleaseEvent","responderRelease","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport { HostElement } from 'universal-test-renderer';\nimport act from './act';\nimport { isElementMounted, isValidElement } 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 { Point, StringWithAutocomplete } from './types';\nimport { nativeState } from './native-state';\nimport { EventBuilder } from './user-event/event-builder';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: HostElement) {\n if (!isValidElement(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([\n 'press',\n 'onPress',\n 'responderGrant',\n 'responderRelease',\n 'longPress',\n 'pressIn',\n 'pressOut',\n]);\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 = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\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: HostElement, 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: 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 const nativeData =\n data.length === 1 &&\n typeof data[0] === 'object' &&\n data[0] !== null &&\n 'nativeEvent' in data[0] &&\n typeof data[0].nativeEvent === 'object'\n ? data[0].nativeEvent\n : null;\n\n let responderGrantEvent = EventBuilder.Common.responderGrant();\n if (nativeData) {\n responderGrantEvent.nativeEvent = {\n ...responderGrantEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderGrant', responderGrantEvent);\n\n fireEvent(element, 'press', ...data);\n\n let responderReleaseEvent = EventBuilder.Common.responderRelease();\n if (nativeData) {\n responderReleaseEvent.nativeEvent = {\n ...responderReleaseEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderRelease', responderReleaseEvent);\n};\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\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":";;;;;;;;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;AACA,IAAAM,aAAA,GAAAN,OAAA;AAA0D,SAAAD,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAInD,SAASG,gBAAgBA,CAACC,OAAoB,EAAE;EACrD,IAAI,CAAC,IAAAC,6BAAc,EAACD,OAAO,CAAC,EAAE;IAC5B,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,CAChD,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,UAAU,CACX,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAA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efault","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","e","__esModule","default","isTouchResponder","element","isValidElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","loose","parent","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","nativeData","length","nativeEvent","responderGrantEvent","EventBuilder","Common","responderGrant","responderReleaseEvent","responderRelease","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","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 { HostElement } from 'universal-test-renderer';\n\nimport act from './act';\nimport { getEventHandler } from './event-handler';\nimport { isElementMounted, isValidElement } 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';\nimport { EventBuilder } from './user-event/event-builder';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: HostElement) {\n if (!isValidElement(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([\n 'press',\n 'onPress',\n 'responderGrant',\n 'responderRelease',\n 'longPress',\n 'pressIn',\n 'pressOut',\n]);\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 = getEventHandler(element, eventName, { loose: true });\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\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\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 const nativeData =\n data.length === 1 &&\n typeof data[0] === 'object' &&\n data[0] !== null &&\n 'nativeEvent' in data[0] &&\n typeof data[0].nativeEvent === 'object'\n ? data[0].nativeEvent\n : null;\n\n const responderGrantEvent = EventBuilder.Common.responderGrant();\n if (nativeData) {\n responderGrantEvent.nativeEvent = {\n ...responderGrantEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderGrant', responderGrantEvent);\n\n fireEvent(element, 'press', ...data);\n\n const responderReleaseEvent = EventBuilder.Common.responderRelease();\n if (nativeData) {\n responderReleaseEvent.nativeEvent = {\n ...responderReleaseEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderRelease', responderReleaseEvent);\n};\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\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;AACA,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;AAEA,IAAAO,aAAA,GAAAP,OAAA;AAA0D,SAAAD,uBAAAS,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAInD,SAASG,gBAAgBA,CAACC,OAAoB,EAAE;EACrD,IAAI,CAAC,IAAAC,6BAAc,EAACD,OAAO,CAAC,EAAE;IAC5B,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,CAChD,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,UAAU,CACX,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAAoB,EACpBU,SAAiB,EACjBC,qBAAmC,EACnC;EACA,IAAIA,qBAAqB,IAAI,IAAI,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC3E,OACE,I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AAMI,CAAC,GAAGJ,aAAa,EAAEI,CAAC;IAC1B,MAAMC,CAAC,GAAGL,aAAa,EAAEK,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,5 +1,5 @@
|
|
|
1
|
-
import { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';
|
|
2
|
-
import { HostElement } from 'universal-test-renderer';
|
|
1
|
+
import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';
|
|
2
|
+
import type { HostElement } from 'universal-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","rootElement","getContainerElement","labelElement","findAll","node","isValidElement","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 {\n AccessibilityRole,\n AccessibilityState,\n AccessibilityValue,\n Role,\n StyleSheet,\n} from 'react-native';\nimport { HostElement } from 'universal-test-renderer';\nimport { getHostSiblings, getContainerElement, isValidElement } 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 rootElement = getContainerElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isValidElement(node) && node.props.nativeID === labelElementId,\n {\n includeHiddenElements: true,\n },\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 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":";;;;;;;;;;;;;;;;;;;;;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,OAA2B,EAC3B;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,E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IAAIH,kBAAkB,EAAEO,GAAG;IAC5CC,IAAI,EAAEJ,aAAa,IAAIJ,kBAAkB,EAAEQ;EAC7C,CAAC;AACH;AAEO,SAASC,qBAAqBA,CAAC3E,OAAoB,EAAsB;EAC9E,OAAOoC,gBAAgB,CAACpC,OAAO,CAAC,IAAI,IAAAgD,2BAAc,EAAChD,OAAO,CAAC;AAC7D;AAIO,MAAMwD,2BAA2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","rootElement","getContainerElement","labelElement","findAll","node","isValidElement","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, isValidElement } 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 rootElement = getContainerElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isValidElement(node) && node.props.nativeID === labelElementId,\n {\n includeHiddenElements: true,\n },\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 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,IA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AAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-tree.js","names":["_universalTestRenderer","require","_screen","isValidElement","element","type","CONTAINER_TYPE","isElementMounted","getContainerElement","screen","container","current","parent","getHostSiblings","hostParent","children","filter","sibling"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["_universalTestRenderer","require","_screen","isValidElement","element","type","CONTAINER_TYPE","isElementMounted","getContainerElement","screen","container","current","parent","getHostSiblings","hostParent","children","filter","sibling"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\nimport { CONTAINER_TYPE } from 'universal-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 isValidElement(element?: HostElement | null): element is HostElement {\n return typeof element?.type === 'string' && element.type !== CONTAINER_TYPE;\n}\n\nexport function isElementMounted(element: HostElement) {\n return getContainerElement(element) === screen.container;\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 getContainerElement(element: HostElement) {\n let current: HostElement | null = element;\n while (current?.parent) {\n current = current.parent;\n }\n\n return current;\n}\n\n/**\n * Returns host siblings for given element.\n * @param element The element start traversing from.\n */\nexport function getHostSiblings(element: HostElement | null): HostElement[] {\n const hostParent = element?.parent ?? null;\n return (\n hostParent?.children.filter(\n (sibling): sibling is HostElement => typeof sibling === 'object' && sibling !== element,\n ) ?? []\n );\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,sBAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAACC,OAA4B,EAA0B;EACnF,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,IAAID,OAAO,CAACC,IAAI,KAAKC,qCAAc;AAC7E;AAEO,SAASC,gBAAgBA,CAACH,OAAoB,EAAE;EACrD,OAAOI,mBAAmB,CAACJ,OAAO,CAAC,KAAKK,cAAM,CAACC,SAAS;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASF,mBAAmBA,CAACJ,OAAoB,EAAE;EACxD,IAAIO,OAA2B,GAAGP,OAAO;EACzC,OAAOO,OAAO,EAAEC,MAAM,EAAE;IACtBD,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAOD,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACT,OAA2B,EAAiB;EAC1E,MAAMU,UAAU,GAAGV,OAAO,EAAEQ,MAAM,IAAI,IAAI;EAC1C,OACEE,UAAU,EAAEC,QAAQ,CAACC,MAAM,CACxBC,OAAO,IAA6B,OAAOA,OAAO,KAAK,QAAQ,IAAIA,OAAO,KAAKb,OAClF,CAAC,IAAI,EAAE;AAEX","ignoreList":[]}
|
package/build/helpers/debug.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { JsonNode } from 'universal-test-renderer';
|
|
2
|
-
import {
|
|
2
|
+
import type { FormatElementOptions } from './format-element';
|
|
3
3
|
export type DebugOptions = {
|
|
4
4
|
message?: string;
|
|
5
|
-
} &
|
|
5
|
+
} & FormatElementOptions;
|
|
6
6
|
/**
|
|
7
7
|
* Log pretty-printed deep test component instance
|
|
8
8
|
*/
|
|
9
|
-
export declare function debug(instance: JsonNode | JsonNode[], options?: DebugOptions
|
|
9
|
+
export declare function debug(instance: JsonNode | JsonNode[], options?: DebugOptions): void;
|
package/build/helpers/debug.js
CHANGED
|
@@ -4,22 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.debug = debug;
|
|
7
|
-
var
|
|
8
|
-
|
|
7
|
+
var _formatElement = require("./format-element");
|
|
8
|
+
var _logger = require("./logger");
|
|
9
9
|
/**
|
|
10
10
|
* Log pretty-printed deep test component instance
|
|
11
11
|
*/
|
|
12
12
|
function debug(instance, options) {
|
|
13
|
-
const message =
|
|
14
|
-
const formatOptions =
|
|
13
|
+
const message = options?.message;
|
|
14
|
+
const formatOptions = {
|
|
15
15
|
mapProps: options?.mapProps
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
if (message) {
|
|
18
|
-
|
|
19
|
-
console.log(`${message}\n\n`, (0, _format.default)(instance, formatOptions));
|
|
18
|
+
_logger.logger.info(`${message}\n\n`, (0, _formatElement.formatJson)(instance, formatOptions));
|
|
20
19
|
} else {
|
|
21
|
-
|
|
22
|
-
console.log((0, _format.default)(instance, formatOptions));
|
|
20
|
+
_logger.logger.info((0, _formatElement.formatJson)(instance, formatOptions));
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
//# sourceMappingURL=debug.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","names":["
|
|
1
|
+
{"version":3,"file":"debug.js","names":["_formatElement","require","_logger","debug","instance","options","message","formatOptions","mapProps","logger","info","formatJson"],"sources":["../../src/helpers/debug.ts"],"sourcesContent":["import type { JsonNode } from 'universal-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(instance: JsonNode | JsonNode[], options?: DebugOptions) {\n const message = options?.message;\n const formatOptions = { mapProps: options?.mapProps };\n\n if (message) {\n logger.info(`${message}\\n\\n`, formatJson(instance, formatOptions));\n } else {\n logger.info(formatJson(instance, formatOptions));\n }\n}\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACO,SAASE,KAAKA,CAACC,QAA+B,EAAEC,OAAsB,EAAE;EAC7E,MAAMC,OAAO,GAAGD,OAAO,EAAEC,OAAO;EAChC,MAAMC,aAAa,GAAG;IAAEC,QAAQ,EAAEH,OAAO,EAAEG;EAAS,CAAC;EAErD,IAAIF,OAAO,EAAE;IACXG,cAAM,CAACC,IAAI,CAAC,GAAGJ,OAAO,MAAM,EAAE,IAAAK,yBAAU,EAACP,QAAQ,EAAEG,aAAa,CAAC,CAAC;EACpE,CAAC,MAAM;IACLE,cAAM,CAACC,IAAI,CAAC,IAAAC,yBAAU,EAACP,QAAQ,EAAEG,aAAa,CAAC,CAAC;EAClD;AACF","ignoreList":[]}
|
package/build/helpers/errors.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.prepareErrorMessage = exports.createQueryByError = void 0;
|
|
|
9
9
|
var _prettyFormat = _interopRequireDefault(require("pretty-format"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
class ErrorWithStack extends Error {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
12
13
|
constructor(message, callsite) {
|
|
13
14
|
super(message);
|
|
14
15
|
if (Error.captureStackTrace) {
|
|
@@ -34,6 +35,8 @@ const prepareErrorMessage = (error, name, value) => {
|
|
|
34
35
|
}
|
|
35
36
|
return errorMessage;
|
|
36
37
|
};
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
37
40
|
exports.prepareErrorMessage = prepareErrorMessage;
|
|
38
41
|
const createQueryByError = (error, callsite) => {
|
|
39
42
|
if (error instanceof Error) {
|
|
@@ -42,10 +45,7 @@ const createQueryByError = (error, callsite) => {
|
|
|
42
45
|
}
|
|
43
46
|
throw new ErrorWithStack(error.message, callsite);
|
|
44
47
|
}
|
|
45
|
-
throw new ErrorWithStack(
|
|
46
|
-
// generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that
|
|
47
|
-
// Converting as any with extra safe optional chaining will do the job just as well
|
|
48
|
-
`Query: caught unknown error type: ${typeof error}, value: ${error?.toString?.()}`, callsite);
|
|
48
|
+
throw new ErrorWithStack(`Query: caught unknown error type: ${typeof error}, value: ${error}`, callsite);
|
|
49
49
|
};
|
|
50
50
|
exports.createQueryByError = createQueryByError;
|
|
51
51
|
function copyStackTrace(target, stackTraceSource) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["_prettyFormat","_interopRequireDefault","require","e","__esModule","default","ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","exports","prepareErrorMessage","error","name","value","errorMessage","replace","toString","prettyFormat","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack"],"sources":["../../src/helpers/errors.ts"],"sourcesContent":["import prettyFormat from 'pretty-format';\n\nexport class ErrorWithStack extends Error {\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport const prepareErrorMessage = (\n // TS states that error caught in a catch close are of type `unknown`\n // most real cases will be `Error`, but better safe than sorry\n error: unknown,\n name?: string,\n value?: unknown,\n): string => {\n let errorMessage: string;\n if (error instanceof Error) {\n // Strip info about custom predicate\n errorMessage = error.message.replace(/ matching custom predicate[^]*/gm, '');\n } else if (error && typeof error === 'object') {\n errorMessage = error.toString();\n } else {\n errorMessage = 'Caught unknown error';\n }\n\n if (name && value) {\n errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;\n }\n return errorMessage;\n};\n\nexport const createQueryByError = (error: unknown, callsite: Function): null => {\n if (error instanceof Error) {\n if (error.message.includes('No instances found')) {\n return null;\n }\n throw new ErrorWithStack(error.message, callsite);\n }\n\n throw new ErrorWithStack(\n
|
|
1
|
+
{"version":3,"file":"errors.js","names":["_prettyFormat","_interopRequireDefault","require","e","__esModule","default","ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","exports","prepareErrorMessage","error","name","value","errorMessage","replace","toString","prettyFormat","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack"],"sources":["../../src/helpers/errors.ts"],"sourcesContent":["import prettyFormat from 'pretty-format';\n\nexport class ErrorWithStack extends Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport const prepareErrorMessage = (\n // TS states that error caught in a catch close are of type `unknown`\n // most real cases will be `Error`, but better safe than sorry\n error: unknown,\n name?: string,\n value?: unknown,\n): string => {\n let errorMessage: string;\n if (error instanceof Error) {\n // Strip info about custom predicate\n errorMessage = error.message.replace(/ matching custom predicate[^]*/gm, '');\n } else if (error && typeof error === 'object') {\n errorMessage = error.toString();\n } else {\n errorMessage = 'Caught unknown error';\n }\n\n if (name && value) {\n errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;\n }\n return errorMessage;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const createQueryByError = (error: unknown, callsite: Function): null => {\n if (error instanceof Error) {\n if (error.message.includes('No instances found')) {\n return null;\n }\n throw new ErrorWithStack(error.message, callsite);\n }\n\n throw new ErrorWithStack(\n `Query: caught unknown error type: ${typeof error}, value: ${error}`,\n callsite,\n );\n};\n\nexport function copyStackTrace(target: unknown, stackTraceSource: Error) {\n if (target instanceof Error && stackTraceSource.stack) {\n target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAyC,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAElC,MAAMG,cAAc,SAASC,KAAK,CAAC;EACxC;EACAC,WAAWA,CAACC,OAA2B,EAAEC,QAAkB,EAAE;IAC3D,KAAK,CAACD,OAAO,CAAC;IACd,IAAIF,KAAK,CAACI,iBAAiB,EAAE;MAC3BJ,KAAK,CAACI,i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AImB,gBAAgB,CAACC,KAAK,EAAE;IACrDF,MAAM,CAACE,KAAK,GAAGD,gBAAgB,CAACC,KAAK,CAACT,OAAO,CAACQ,gBAAgB,CAACjB,OAAO,EAAEgB,MAAM,CAAChB,OAAO,CAAC;EACzF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-all.js","names":["_config","require","_accessibility","_componentTree","findAll","root","predicate","options","results","findAllInternal","includeHiddenElements","hidden","getConfig","defaultIncludeHiddenElements","cache","WeakMap","filter","element","isHiddenFromAccessibility","node","indent","matchingDescendants","children","forEach","child","push","matchDeepestOnly","length","isValidElement"],"sources":["../../src/helpers/find-all.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport { getConfig } from '../config';\nimport { isHiddenFromAccessibility } from './accessibility';\nimport { isValidElement } from './component-tree';\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 results = findAllInternal(root, predicate, options);\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\n// Extracted from React Test Renderer\n// src: https://github.com/facebook/react/blob/8e2bde6f2751aa6335f3cef488c05c3ea08e074a/packages/react-test-renderer/src/ReactTestRenderer.js#L402\nfunction findAllInternal(\n node: HostElement,\n predicate: (element: HostElement) => boolean,\n options?: FindAllOptions,\n indent: string = '',\n): HostElement[] {\n const results: HostElement[] = [];\n\n // Match descendants first but do not add them to results yet.\n const matchingDescendants: HostElement[] = [];\n node.children.forEach((child) => {\n if (typeof child === 'string') {\n return;\n }\n matchingDescendants.push(...findAllInternal(child, predicate, options, indent + ' '));\n });\n\n if (\n // When matchDeepestOnly = true: add current element only if no descendants match\n (!options?.matchDeepestOnly || matchingDescendants.length === 0) &&\n isValidElement(node) &&\n predicate(node)\n ) {\n results.push(node);\n }\n\n // Add matching descendants after element to preserve original tree walk order.\n results.push(...matchingDescendants);\n\n return results;\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"find-all.js","names":["_config","require","_accessibility","_componentTree","findAll","root","predicate","options","results","findAllInternal","includeHiddenElements","hidden","getConfig","defaultIncludeHiddenElements","cache","WeakMap","filter","element","isHiddenFromAccessibility","node","indent","matchingDescendants","children","forEach","child","push","matchDeepestOnly","length","isValidElement"],"sources":["../../src/helpers/find-all.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { getConfig } from '../config';\nimport { isHiddenFromAccessibility } from './accessibility';\nimport { isValidElement } from './component-tree';\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 results = findAllInternal(root, predicate, options);\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\n// Extracted from React Test Renderer\n// src: https://github.com/facebook/react/blob/8e2bde6f2751aa6335f3cef488c05c3ea08e074a/packages/react-test-renderer/src/ReactTestRenderer.js#L402\nfunction findAllInternal(\n node: HostElement,\n predicate: (element: HostElement) => boolean,\n options?: FindAllOptions,\n indent: string = '',\n): HostElement[] {\n const results: HostElement[] = [];\n\n // Match descendants first but do not add them to results yet.\n const matchingDescendants: HostElement[] = [];\n node.children.forEach((child) => {\n if (typeof child === 'string') {\n return;\n }\n matchingDescendants.push(...findAllInternal(child, predicate, options, indent + ' '));\n });\n\n if (\n // When matchDeepestOnly = true: add current element only if no descendants match\n (!options?.matchDeepestOnly || matchingDescendants.length === 0) &&\n isValidElement(node) &&\n predicate(node)\n ) {\n results.push(node);\n }\n\n // Add matching descendants after element to preserve original tree walk order.\n results.push(...matchingDescendants);\n\n return results;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAaO,SAASG,OAAOA,CACrBC,IAAiB,EACjBC,SAA4C,EAC5CC,OAAwB,EACT;EACf,MAAMC,OAAO,GAAGC,eAAe,CAACJ,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC;EAEzD,MAAMG,qBAAqB,GACzBH,OAAO,EAAEG,qBAAqB,IAAIH,OAAO,EAAEI,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;;AAEA;AACA;AACA,SAASL,eAAeA,CACtBU,IAAiB,EACjBb,SAA4C,EAC5CC,OAAwB,EACxBa,MAAc,GAAG,EAAE,EACJ;EACf,MAAMZ,OAAsB,GAAG,EAAE;;EAEjC;EACA,MAAMa,mBAAkC,GAAG,EAAE;EAC7CF,IAAI,CAACG,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAK;IAC/B,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B;IACF;IACAH,mBAAmB,CAACI,IAAI,CAAC,GAAGhB,eAAe,CAACe,KAAK,EAAElB,SAAS,EAAEC,OAAO,EAAEa,MAAM,GAAG,IAAI,CAAC,CAAC;EACxF,CAAC,CAAC;EAEF;EACE;EACA,CAAC,CAACb,OAAO,EAAEmB,gBAAgB,IAAIL,mBAAmB,CAACM,MAAM,KAAK,CAAC,KAC/D,IAAAC,6BAAc,EAACT,IAAI,CAAC,IACpBb,SAAS,CAACa,IAAI,CAAC,EACf;IACAX,OAAO,CAACiB,IAAI,CAACN,IAAI,CAAC;EACpB;;EAEA;EACAX,OAAO,CAACiB,IAAI,CAAC,GAAGJ,mBAAmB,CAAC;EAEpC,OAAOb,OAAO;AAChB","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HostNode, JsonNode } from 'universal-test-renderer';
|
|
2
|
+
import type { MapPropsFunction } from './map-props';
|
|
3
|
+
export type FormatElementOptions = {
|
|
4
|
+
/** Minimize used space. */
|
|
5
|
+
compact?: boolean;
|
|
6
|
+
/** Highlight the output. */
|
|
7
|
+
highlight?: boolean;
|
|
8
|
+
/** Filter or map props to display. */
|
|
9
|
+
mapProps?: MapPropsFunction | null;
|
|
10
|
+
};
|
|
11
|
+
/***
|
|
12
|
+
* Format given element as a pretty-printed string.
|
|
13
|
+
*
|
|
14
|
+
* @param element Element to format.
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatElement(element: HostNode | null, { compact, highlight, mapProps }?: FormatElementOptions): string;
|
|
17
|
+
export declare function formatElementList(elements: HostNode[], options?: FormatElementOptions): string;
|
|
18
|
+
export declare function formatJson(json: JsonNode | JsonNode[], { compact, highlight, mapProps }?: FormatElementOptions): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatElement = formatElement;
|
|
7
|
+
exports.formatElementList = formatElementList;
|
|
8
|
+
exports.formatJson = formatJson;
|
|
9
|
+
var _prettyFormat = _interopRequireWildcard(require("pretty-format"));
|
|
10
|
+
var _mapProps = require("./map-props");
|
|
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; }
|
|
13
|
+
/***
|
|
14
|
+
* Format given element as a pretty-printed string.
|
|
15
|
+
*
|
|
16
|
+
* @param element Element to format.
|
|
17
|
+
*/
|
|
18
|
+
function formatElement(element, {
|
|
19
|
+
compact,
|
|
20
|
+
highlight = true,
|
|
21
|
+
mapProps = _mapProps.defaultMapProps
|
|
22
|
+
} = {}) {
|
|
23
|
+
if (element == null) {
|
|
24
|
+
return '(null)';
|
|
25
|
+
}
|
|
26
|
+
if (typeof element === 'string') {
|
|
27
|
+
return element;
|
|
28
|
+
}
|
|
29
|
+
const childrenToDisplay = element.children.filter(child => typeof child === 'string');
|
|
30
|
+
return (0, _prettyFormat.default)({
|
|
31
|
+
// This prop is needed persuade the prettyFormat that the element is
|
|
32
|
+
// a ReactTestRendererJSON instance, so it is formatted as JSX.
|
|
33
|
+
$$typeof: Symbol.for('react.test.json'),
|
|
34
|
+
type: `${element.type}`,
|
|
35
|
+
props: mapProps ? mapProps(element.props) : element.props,
|
|
36
|
+
children: childrenToDisplay
|
|
37
|
+
},
|
|
38
|
+
// See: https://www.npmjs.com/package/pretty-format#usage-with-options
|
|
39
|
+
{
|
|
40
|
+
plugins: [_prettyFormat.plugins.ReactTestComponent],
|
|
41
|
+
printFunctionName: false,
|
|
42
|
+
printBasicPrototype: false,
|
|
43
|
+
highlight: highlight,
|
|
44
|
+
min: compact
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function formatElementList(elements, options) {
|
|
48
|
+
if (elements.length === 0) {
|
|
49
|
+
return '(no elements)';
|
|
50
|
+
}
|
|
51
|
+
return elements.map(element => formatElement(element, options)).join('\n');
|
|
52
|
+
}
|
|
53
|
+
function formatJson(json, {
|
|
54
|
+
compact,
|
|
55
|
+
highlight = true,
|
|
56
|
+
mapProps = _mapProps.defaultMapProps
|
|
57
|
+
} = {}) {
|
|
58
|
+
return (0, _prettyFormat.default)(json, {
|
|
59
|
+
plugins: [getElementJsonPlugin(mapProps), _prettyFormat.plugins.ReactElement],
|
|
60
|
+
highlight: highlight,
|
|
61
|
+
printBasicPrototype: false,
|
|
62
|
+
min: compact
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function getElementJsonPlugin(mapProps) {
|
|
66
|
+
return {
|
|
67
|
+
test: val => _prettyFormat.plugins.ReactTestComponent.test(val),
|
|
68
|
+
serialize: (val, config, indentation, depth, refs, printer) => {
|
|
69
|
+
let newVal = val;
|
|
70
|
+
if (mapProps && val.props) {
|
|
71
|
+
newVal = {
|
|
72
|
+
...val,
|
|
73
|
+
props: mapProps(val.props)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return _prettyFormat.plugins.ReactTestComponent.serialize(newVal, config, indentation, depth, refs, printer);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=format-element.js.map
|