@testing-library/react-native 12.2.2 → 12.3.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.
Files changed (164) hide show
  1. package/build/act.js +1 -2
  2. package/build/act.js.map +1 -1
  3. package/build/config.d.ts +2 -0
  4. package/build/config.js.map +1 -1
  5. package/build/fireEvent.js +3 -3
  6. package/build/fireEvent.js.map +1 -1
  7. package/build/helpers/accessiblity.d.ts +11 -0
  8. package/build/helpers/accessiblity.js +108 -8
  9. package/build/helpers/accessiblity.js.map +1 -1
  10. package/build/helpers/component-tree.d.ts +7 -0
  11. package/build/helpers/component-tree.js +18 -0
  12. package/build/helpers/component-tree.js.map +1 -1
  13. package/build/helpers/format-default.d.ts +1 -2
  14. package/build/helpers/format-default.js +22 -13
  15. package/build/helpers/format-default.js.map +1 -1
  16. package/build/helpers/format.js +4 -8
  17. package/build/helpers/format.js.map +1 -1
  18. package/build/helpers/host-component-names.d.ts +10 -0
  19. package/build/helpers/host-component-names.js +27 -3
  20. package/build/helpers/host-component-names.js.map +1 -1
  21. package/build/helpers/matchers/accessibilityState.js +3 -3
  22. package/build/helpers/matchers/accessibilityState.js.map +1 -1
  23. package/build/helpers/matchers/accessibilityValue.js +3 -2
  24. package/build/helpers/matchers/accessibilityValue.js.map +1 -1
  25. package/build/helpers/matchers/matchLabelText.d.ts +1 -1
  26. package/build/helpers/matchers/matchLabelText.js +5 -8
  27. package/build/helpers/matchers/matchLabelText.js.map +1 -1
  28. package/build/helpers/matchers/matchTextContent.js +2 -2
  29. package/build/helpers/matchers/matchTextContent.js.map +1 -1
  30. package/build/helpers/object.d.ts +1 -0
  31. package/build/helpers/object.js +16 -0
  32. package/build/helpers/object.js.map +1 -0
  33. package/build/helpers/{getTextContent.js → text-content.js} +1 -1
  34. package/build/helpers/text-content.js.map +1 -0
  35. package/build/helpers/text-input.d.ts +3 -0
  36. package/build/helpers/text-input.js +21 -0
  37. package/build/helpers/text-input.js.map +1 -0
  38. package/build/helpers/wrap-async.d.ts +7 -0
  39. package/build/helpers/wrap-async.js +45 -0
  40. package/build/helpers/wrap-async.js.map +1 -0
  41. package/build/matchers/extend-expect.d.js +2 -0
  42. package/build/matchers/extend-expect.d.js.map +1 -0
  43. package/build/matchers/extend-expect.d.ts +2 -0
  44. package/build/matchers/extend-expect.js +38 -0
  45. package/build/matchers/extend-expect.js.map +1 -0
  46. package/build/matchers/index.d.ts +15 -0
  47. package/build/matchers/index.js +117 -0
  48. package/build/matchers/index.js.map +1 -0
  49. package/build/matchers/to-be-busy.d.ts +6 -0
  50. package/build/matchers/to-be-busy.js +20 -0
  51. package/build/matchers/to-be-busy.js.map +1 -0
  52. package/build/matchers/to-be-checked.d.ts +6 -0
  53. package/build/matchers/to-be-checked.js +31 -0
  54. package/build/matchers/to-be-checked.js.map +1 -0
  55. package/build/matchers/to-be-collapsed.d.ts +6 -0
  56. package/build/matchers/to-be-collapsed.js +20 -0
  57. package/build/matchers/to-be-collapsed.js.map +1 -0
  58. package/build/matchers/to-be-disabled.d.ts +10 -0
  59. package/build/matchers/to-be-disabled.js +52 -0
  60. package/build/matchers/to-be-disabled.js.map +1 -0
  61. package/build/matchers/to-be-empty-element.d.ts +6 -0
  62. package/build/matchers/to-be-empty-element.js +20 -0
  63. package/build/matchers/to-be-empty-element.js.map +1 -0
  64. package/build/matchers/to-be-expanded.d.ts +6 -0
  65. package/build/matchers/to-be-expanded.js +20 -0
  66. package/build/matchers/to-be-expanded.js.map +1 -0
  67. package/build/matchers/to-be-on-the-screen.d.ts +6 -0
  68. package/build/matchers/to-be-on-the-screen.js +29 -0
  69. package/build/matchers/to-be-on-the-screen.js.map +1 -0
  70. package/build/matchers/to-be-partially-checked.d.ts +6 -0
  71. package/build/matchers/to-be-partially-checked.js +28 -0
  72. package/build/matchers/to-be-partially-checked.js.map +1 -0
  73. package/build/matchers/to-be-selected.d.ts +6 -0
  74. package/build/matchers/to-be-selected.js +20 -0
  75. package/build/matchers/to-be-selected.js.map +1 -0
  76. package/build/matchers/to-be-visible.d.ts +6 -0
  77. package/build/matchers/to-be-visible.js +56 -0
  78. package/build/matchers/to-be-visible.js.map +1 -0
  79. package/build/matchers/to-contain-element.d.ts +6 -0
  80. package/build/matchers/to-contain-element.js +26 -0
  81. package/build/matchers/to-contain-element.js.map +1 -0
  82. package/build/matchers/to-have-display-value.d.ts +7 -0
  83. package/build/matchers/to-have-display-value.js +26 -0
  84. package/build/matchers/to-have-display-value.js.map +1 -0
  85. package/build/matchers/to-have-prop.d.ts +6 -0
  86. package/build/matchers/to-have-prop.js +35 -0
  87. package/build/matchers/to-have-prop.js.map +1 -0
  88. package/build/matchers/to-have-style.d.ts +8 -0
  89. package/build/matchers/to-have-style.js +52 -0
  90. package/build/matchers/to-have-style.js.map +1 -0
  91. package/build/matchers/to-have-text-content.d.ts +7 -0
  92. package/build/matchers/to-have-text-content.js +21 -0
  93. package/build/matchers/to-have-text-content.js.map +1 -0
  94. package/build/matchers/utils.d.ts +18 -0
  95. package/build/matchers/utils.js +90 -0
  96. package/build/matchers/utils.js.map +1 -0
  97. package/build/matches.d.ts +1 -1
  98. package/build/matches.js.map +1 -1
  99. package/build/queries/displayValue.js +4 -3
  100. package/build/queries/displayValue.js.map +1 -1
  101. package/build/queries/labelText.js +2 -2
  102. package/build/queries/labelText.js.map +1 -1
  103. package/build/queries/role.js +1 -1
  104. package/build/queries/role.js.map +1 -1
  105. package/build/react-versions.js +2 -2
  106. package/build/react-versions.js.map +1 -1
  107. package/build/render.d.ts +12 -48
  108. package/build/render.js +5 -4
  109. package/build/render.js.map +1 -1
  110. package/build/screen.js +1 -2
  111. package/build/screen.js.map +1 -1
  112. package/build/shallow.js +2 -2
  113. package/build/shallow.js.map +1 -1
  114. package/build/test-utils/events.d.ts +1 -2
  115. package/build/test-utils/events.js.map +1 -1
  116. package/build/user-event/clear.js +2 -1
  117. package/build/user-event/clear.js.map +1 -1
  118. package/build/user-event/event-builder/common.js +1 -2
  119. package/build/user-event/event-builder/common.js.map +1 -1
  120. package/build/user-event/event-builder/index.d.ts +30 -0
  121. package/build/user-event/event-builder/index.js +3 -2
  122. package/build/user-event/event-builder/index.js.map +1 -1
  123. package/build/user-event/event-builder/scroll-view.d.ts +42 -0
  124. package/build/user-event/event-builder/scroll-view.js +52 -0
  125. package/build/user-event/event-builder/scroll-view.js.map +1 -0
  126. package/build/user-event/event-builder/text-input.js +1 -2
  127. package/build/user-event/event-builder/text-input.js.map +1 -1
  128. package/build/user-event/index.d.ts +2 -0
  129. package/build/user-event/index.js +3 -3
  130. package/build/user-event/index.js.map +1 -1
  131. package/build/user-event/press/constants.js +2 -4
  132. package/build/user-event/press/constants.js.map +1 -1
  133. package/build/user-event/press/press.js +11 -14
  134. package/build/user-event/press/press.js.map +1 -1
  135. package/build/user-event/scroll/index.d.ts +1 -0
  136. package/build/user-event/scroll/index.js +19 -0
  137. package/build/user-event/scroll/index.js.map +1 -0
  138. package/build/user-event/scroll/scrollTo.d.ts +16 -0
  139. package/build/user-event/scroll/scrollTo.js +82 -0
  140. package/build/user-event/scroll/scrollTo.js.map +1 -0
  141. package/build/user-event/scroll/state.d.ts +4 -0
  142. package/build/user-event/scroll/state.js +18 -0
  143. package/build/user-event/scroll/state.js.map +1 -0
  144. package/build/user-event/scroll/utils.d.ts +20 -0
  145. package/build/user-event/scroll/utils.js +68 -0
  146. package/build/user-event/scroll/utils.js.map +1 -0
  147. package/build/user-event/setup/setup.d.ts +8 -0
  148. package/build/user-event/setup/setup.js +34 -6
  149. package/build/user-event/setup/setup.js.map +1 -1
  150. package/build/user-event/type/type.js +2 -1
  151. package/build/user-event/type/type.js.map +1 -1
  152. package/build/user-event/utils/index.d.ts +0 -1
  153. package/build/user-event/utils/index.js +0 -11
  154. package/build/user-event/utils/index.js.map +1 -1
  155. package/build/waitFor.js +2 -26
  156. package/build/waitFor.js.map +1 -1
  157. package/build/within.js +1 -2
  158. package/build/within.js.map +1 -1
  159. package/package.json +23 -37
  160. package/build/helpers/getTextContent.js.map +0 -1
  161. package/build/user-event/utils/host-components.d.ts +0 -2
  162. package/build/user-event/utils/host-components.js +0 -11
  163. package/build/user-event/utils/host-components.js.map +0 -1
  164. /package/build/helpers/{getTextContent.d.ts → text-content.d.ts} +0 -0
package/build/act.js CHANGED
@@ -67,6 +67,5 @@ function withGlobalActEnvironment(actImplementation) {
67
67
  };
68
68
  }
69
69
  const act = (0, _reactVersions.checkReactVersionAtLeast)(18, 0) ? withGlobalActEnvironment(_reactTestRenderer.act) : _reactTestRenderer.act;
70
- var _default = act;
71
- exports.default = _default;
70
+ var _default = exports.default = act;
72
71
  //# sourceMappingURL=act.js.map
package/build/act.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"act.js","names":["_reactTestRenderer","require","_reactVersions","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","act","checkReactVersionAtLeast","reactTestRendererAct","_default","exports","default"],"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/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js\nimport { act as reactTestRendererAct } from 'react-test-renderer';\nimport { checkReactVersionAtLeast } from './react-versions';\n\ntype ReactAct = typeof reactTestRendererAct;\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 // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do\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 if (\n result !== null &&\n typeof result === 'object' &&\n // @ts-expect-error this should be a promise or thenable\n // eslint-disable-next-line promise/prefer-await-to-then\n typeof result.then === 'function'\n ) {\n callbackNeedsToBeAwaited = true;\n }\n return result;\n });\n\n if (callbackNeedsToBeAwaited) {\n const thenable = actResult;\n return {\n then: (\n resolve: (value: never) => never,\n reject: (value: never) => never\n ) => {\n // eslint-disable-next-line\n thenable.then(\n // eslint-disable-next-line promise/always-return\n (returnValue) => {\n setIsReactActEnvironment(previousActEnvironment);\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\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: ReactAct = checkReactVersionAtLeast(18, 0)\n ? (withGlobalActEnvironment(reactTestRendererAct) as ReactAct)\n : reactTestRendererAct;\n\nexport default act;\nexport {\n setIsReactActEnvironment as setReactActEnvironment,\n getIsReactActEnvironment,\n};\n"],"mappings":";;;;;;;;AAEA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAHA;AACA;;AAMA;;AAKA,SAASE,wBAAwBA,CAACC,qBAA0C,EAAE;EAC5EC,UAAU,CAACC,wBAAwB,GAAGF,qBAAqB;AAC7D;AAEA,SAASG,wBAAwBA,CAAA,EAAG;EAClC,OAAOF,UAAU,CAACC,wBAAwB;AAC5C;AAEA,SAASE,wBAAwBA,CAACC,iBAA2B,EAAE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AA"}
1
+ {"version":3,"file":"act.js","names":["_reactTestRenderer","require","_reactVersions","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","act","checkReactVersionAtLeast","reactTestRendererAct","_default","exports","default"],"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/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js\nimport { act as reactTestRendererAct } from 'react-test-renderer';\nimport { checkReactVersionAtLeast } from './react-versions';\n\ntype ReactAct = typeof reactTestRendererAct;\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 // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do\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 if (\n result !== null &&\n typeof result === 'object' &&\n // @ts-expect-error this should be a promise or thenable\n // eslint-disable-next-line promise/prefer-await-to-then\n typeof result.then === 'function'\n ) {\n callbackNeedsToBeAwaited = true;\n }\n return result;\n });\n\n if (callbackNeedsToBeAwaited) {\n const thenable = actResult;\n return {\n then: (\n resolve: (value: never) => never,\n reject: (value: never) => never\n ) => {\n // eslint-disable-next-line\n thenable.then(\n // eslint-disable-next-line promise/always-return\n (returnValue) => {\n setIsReactActEnvironment(previousActEnvironment);\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\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: ReactAct = checkReactVersionAtLeast(18, 0)\n ? (withGlobalActEnvironment(reactTestRendererAct) as ReactAct)\n : reactTestRendererAct;\n\nexport default act;\nexport {\n setIsReactActEnvironment as setReactActEnvironment,\n getIsReactActEnvironment,\n};\n"],"mappings":";;;;;;;;AAEA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAHA;AACA;;AAMA;;AAKA,SAASE,wBAAwBA,CAACC,qBAA0C,EAAE;EAC5EC,UAAU,CAACC,wBAAwB,GAAGF,qBAAqB;AAC7D;AAEA,SAASG,wBAAwBA,CAAA,EAAG;EAClC,OAAOF,UAAU,CAACC,wBAAwB;AAC5C;AAEA,SAASE,wBAAwBA,CAACC,iBAA2B,EAAE;EAC7D,OAAQC,QAAiC,IAAK;IAC5C,MAAMC,sBAAsB,GAAGJ,wBAAwB,CAAC,CAAC;IACzDJ,wBAAwB,CAAC,IAAI,CAAC;;IAE9B;IACA,IAAI;MACF;MACA,IAAIS,wBAAwB,GAAG,KAAK;MACpC,MAAMC,SAAS,GAAGJ,iBAAiB,CAAC,MAAM;QACxC,MAAMK,MAAM,GAAGJ,QAAQ,CAAC,CAAC;QACzB,IACEI,MAAM,KAAK,IAAI,IACf,OAAOA,MAAM,KAAK,QAAQ;QAC1B;QACA;QACA,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EACjC;UACAH,wBAAwB,GAAG,IAAI;QACjC;QACA,OAAOE,MAAM;MACf,CAAC,CAAC;MAEF,IAAIF,wBAAwB,EAAE;QAC5B,MAAMI,QAAQ,GAAGH,SAAS;QAC1B,OAAO;UACLE,IAAI,EAAEA,CACJE,OAAgC,EAChCC,MAA+B,KAC5B;YACH;YACAF,QAAQ,CAACD,IAAI;YACX;YACCI,WAAW,IAAK;cACfhB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChDM,OAAO,CAACE,WAAW,CAAC;YACtB,CAAC,EACAC,KAAK,IAAK;cACTjB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChDO,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,GAAa,GAAG,IAAAC,uCAAwB,EAAC,EAAE,EAAE,CAAC,CAAC,GAChDd,wBAAwB,CAACe,sBAAoB,CAAC,GAC/CA,sBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEVL,GAAG"}
package/build/config.d.ts CHANGED
@@ -18,6 +18,8 @@ export type HostComponentNames = {
18
18
  text: string;
19
19
  textInput: string;
20
20
  switch: string;
21
+ scrollView: string;
22
+ modal: string;
21
23
  };
22
24
  export type InternalConfig = Config & {
23
25
  /** Names for key React Native host components. */
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultHidden","restOptions","configureInternal","option","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debugDeep';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nexport type HostComponentNames = {\n text: string;\n textInput: string;\n switch: string;\n};\n\nexport type InternalConfig = Config & {\n /** Names for key React Native host components. */\n hostComponentNames?: HostComponentNames;\n};\n\nconst defaultConfig: InternalConfig = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const { 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 configureInternal(option: Partial<InternalConfig>) {\n config = {\n ...config,\n ...option,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;;AA6BA,MAAMA,aAA6B,GAAG;EACpCC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE;AAChC,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGH;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASI,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMH,4BAA4B,GAChCK,WAAW,CAACL,4BAA4B,IACxCI,aAAa,IACbH,MAAM,CAACD,4BAA4B;EAErCC,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdL;EACF,CAAC;AACH;AAEO,SAASM,iBAAiBA,CAACC,MAA+B,EAAE;EACjEN,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGM;EACL,CAAC;AACH;AAEO,SAASC,eAAeA,CAAA,EAAG;EAChCP,MAAM,GAAG;IAAE,GAAGH;EAAc,CAAC;AAC/B;AAEO,SAASW,SAASA,CAAA,EAAG;EAC1B,OAAOR,MAAM;AACf"}
1
+ {"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultHidden","restOptions","configureInternal","option","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debugDeep';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nexport type HostComponentNames = {\n text: string;\n textInput: string;\n switch: string;\n scrollView: string;\n modal: string;\n};\n\nexport type InternalConfig = Config & {\n /** Names for key React Native host components. */\n hostComponentNames?: HostComponentNames;\n};\n\nconst defaultConfig: InternalConfig = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const { 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 configureInternal(option: Partial<InternalConfig>) {\n config = {\n ...config,\n ...option,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;;AA+BA,MAAMA,aAA6B,GAAG;EACpCC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE;AAChC,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGH;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASI,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMH,4BAA4B,GAChCK,WAAW,CAACL,4BAA4B,IACxCI,aAAa,IACbH,MAAM,CAACD,4BAA4B;EAErCC,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdL;EACF,CAAC;AACH;AAEO,SAASM,iBAAiBA,CAACC,MAA+B,EAAE;EACjEN,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGM;EACL,CAAC;AACH;AAEO,SAASC,eAAeA,CAAA,EAAG;EAChCP,MAAM,GAAG;IAAE,GAAGH;EAAc,CAAC;AAC/B;AAEO,SAASW,SAASA,CAAA,EAAG;EAC1B,OAAOR,MAAM;AACf"}
@@ -10,6 +10,7 @@ var _act = _interopRequireDefault(require("./act"));
10
10
  var _componentTree = require("./helpers/component-tree");
11
11
  var _hostComponentNames = require("./helpers/host-component-names");
12
12
  var _pointerEvents = require("./helpers/pointer-events");
13
+ var _textInput = require("./helpers/text-input");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  function isTouchResponder(element) {
15
16
  if (!(0, _componentTree.isHostElement)(element)) {
@@ -35,7 +36,7 @@ const eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);
35
36
  const textInputEventsIgnoringEditableProp = new Set(['contentSizeChange', 'onContentSizeChange', 'layout', 'onLayout', 'scroll', 'onScroll']);
36
37
  function isEventEnabled(element, eventName, nearestTouchResponder) {
37
38
  if ((0, _hostComponentNames.isHostTextInput)(nearestTouchResponder)) {
38
- return nearestTouchResponder?.props.editable !== false || textInputEventsIgnoringEditableProp.has(eventName);
39
+ return (0, _textInput.isTextInputEditable)(nearestTouchResponder) || textInputEventsIgnoringEditableProp.has(eventName);
39
40
  }
40
41
  if (eventsAffectedByPointerEventsProp.has(eventName) && !(0, _pointerEvents.isPointerEventEnabled)(element)) {
41
42
  return false;
@@ -88,6 +89,5 @@ function fireEvent(element, eventName, ...data) {
88
89
  fireEvent.press = (element, ...data) => fireEvent(element, 'press', ...data);
89
90
  fireEvent.changeText = (element, ...data) => fireEvent(element, 'changeText', ...data);
90
91
  fireEvent.scroll = (element, ...data) => fireEvent(element, 'scroll', ...data);
91
- var _default = fireEvent;
92
- exports.default = _default;
92
+ var _default = exports.default = fireEvent;
93
93
  //# sourceMappingURL=fireEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fireEvent.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","obj","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","editable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","returnValue","act","press","changeText","scroll","_default","exports"],"sources":["../src/fireEvent.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 { isHostElement } from './helpers/component-tree';\nimport { isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return (\n Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element)\n );\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 nearestTouchResponder?.props.editable !== false ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (\n eventsAffectedByPointerEventsProp.has(eventName) &&\n !isPointerEventEnabled(element)\n ) {\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)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder))\n return handler;\n\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// Allows any string but will provide autocomplete for type T\ntype StringWithAutoComplete<T> = T | (string & Record<never, never>);\n\n// String union type of keys of T that start with on, stripped from on\ntype OnKeys<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}`\n ? Uncapitalize<Rest>\n : never]: T[K];\n};\n\ntype EventName = StringWithAutoComplete<\n | OnKeys<ViewProps>\n | OnKeys<TextProps>\n | OnKeys<TextInputProps>\n | OnKeys<PressableProps>\n | OnKeys<ScrollViewProps>\n>;\n\nfunction fireEvent(\n element: ReactTestInstance,\n eventName: EventName,\n ...data: unknown[]\n) {\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n 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"],"mappings":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AAAiE,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAI1D,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OACEE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,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EAAE,GAAG8B,IAAe,KAC/DD,SAAS,CAAC7B,OAAO,EAAE,OAAO,EAAE,GAAG8B,IAAI,CAAC;AAEtCD,SAAS,CAACK,UAAU,GAAG,CAAClC,OAA0B,EAAE,GAAG8B,IAAe,KACpED,SAAS,CAAC7B,OAAO,EAAE,YAAY,EAAE,GAAG8B,IAAI,CAAC;AAE3CD,SAAS,CAACM,MAAM,GAAG,CAACnC,OAA0B,EAAE,GAAG8B,IAAe,KAChED,SAAS,CAAC7B,OAAO,EAAE,QAAQ,EAAE,GAAG8B,IAAI,CAAC;AAAC,IAAAM,QAAA,GAEzBP,SAAS;AAAAQ,OAAA,CAAAvC,OAAA,GAAAsC,QAAA"}
1
+ {"version":3,"file":"fireEvent.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","obj","__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","returnValue","act","press","changeText","scroll","_default","exports"],"sources":["../src/fireEvent.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 { isHostElement } from './helpers/component-tree';\nimport { isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return (\n Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element)\n );\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 (\n eventsAffectedByPointerEventsProp.has(eventName) &&\n !isPointerEventEnabled(element)\n ) {\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)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder))\n return handler;\n\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// Allows any string but will provide autocomplete for type T\ntype StringWithAutoComplete<T> = T | (string & Record<never, never>);\n\n// String union type of keys of T that start with on, stripped from on\ntype OnKeys<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}`\n ? Uncapitalize<Rest>\n : never]: T[K];\n};\n\ntype EventName = StringWithAutoComplete<\n | OnKeys<ViewProps>\n | OnKeys<TextProps>\n | OnKeys<TextInputProps>\n | OnKeys<PressableProps>\n | OnKeys<ScrollViewProps>\n>;\n\nfunction fireEvent(\n element: ReactTestInstance,\n eventName: EventName,\n ...data: unknown[]\n) {\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n 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"],"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;AAA2D,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIpD,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OACEE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AAEhF;;AAEA;AACA;AACA;A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AAE,GAAG8B,IAAI,CAAC;AAEtCD,SAAS,CAACK,UAAU,GAAG,CAAClC,OAA0B,EAAE,GAAG8B,IAAe,KACpED,SAAS,CAAC7B,OAAO,EAAE,YAAY,EAAE,GAAG8B,IAAI,CAAC;AAE3CD,SAAS,CAACM,MAAM,GAAG,CAACnC,OAA0B,EAAE,GAAG8B,IAAe,KAChED,SAAS,CAAC7B,OAAO,EAAE,QAAQ,EAAE,GAAG8B,IAAI,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAvC,OAAA,GAEzB+B,SAAS"}
@@ -9,4 +9,15 @@ export declare function isHiddenFromAccessibility(element: ReactTestInstance | n
9
9
  /** RTL-compatitibility alias for `isHiddenFromAccessibility` */
10
10
  export declare const isInaccessible: typeof isHiddenFromAccessibility;
11
11
  export declare function isAccessibilityElement(element: ReactTestInstance | null): boolean;
12
+ export declare function getAccessibilityRole(element: ReactTestInstance): string | undefined;
13
+ export declare function getAccessibilityViewIsModal(element: ReactTestInstance): any;
14
+ export declare function getAccessibilityLabel(element: ReactTestInstance): string | undefined;
15
+ export declare function getAccessibilityLabelledBy(element: ReactTestInstance): string | undefined;
16
+ export declare function getAccessibilityState(element: ReactTestInstance): AccessibilityState | undefined;
17
+ export declare function getAccessibilityCheckedState(element: ReactTestInstance): AccessibilityState['checked'];
18
+ export declare function getAccessibilityValue(element: ReactTestInstance): AccessibilityValue | undefined;
19
+ export declare function isElementBusy(element: ReactTestInstance): NonNullable<AccessibilityState['busy']>;
20
+ export declare function isElementCollapsed(element: ReactTestInstance): NonNullable<AccessibilityState['expanded']>;
21
+ export declare function isElementExpanded(element: ReactTestInstance): NonNullable<AccessibilityState['expanded']>;
22
+ export declare function isElementSelected(element: ReactTestInstance): NonNullable<AccessibilityState['selected']>;
12
23
  export {};
@@ -4,16 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.accessiblityValueKeys = exports.accessibilityStateKeys = void 0;
7
+ exports.getAccessibilityCheckedState = getAccessibilityCheckedState;
8
+ exports.getAccessibilityLabel = getAccessibilityLabel;
9
+ exports.getAccessibilityLabelledBy = getAccessibilityLabelledBy;
10
+ exports.getAccessibilityRole = getAccessibilityRole;
11
+ exports.getAccessibilityState = getAccessibilityState;
12
+ exports.getAccessibilityValue = getAccessibilityValue;
13
+ exports.getAccessibilityViewIsModal = getAccessibilityViewIsModal;
7
14
  exports.isAccessibilityElement = isAccessibilityElement;
15
+ exports.isElementBusy = isElementBusy;
16
+ exports.isElementCollapsed = isElementCollapsed;
17
+ exports.isElementExpanded = isElementExpanded;
18
+ exports.isElementSelected = isElementSelected;
8
19
  exports.isHiddenFromAccessibility = isHiddenFromAccessibility;
9
20
  exports.isInaccessible = void 0;
10
21
  var _reactNative = require("react-native");
11
22
  var _componentTree = require("./component-tree");
12
23
  var _hostComponentNames = require("./host-component-names");
13
- const accessibilityStateKeys = ['disabled', 'selected', 'checked', 'busy', 'expanded'];
14
- exports.accessibilityStateKeys = accessibilityStateKeys;
15
- const accessiblityValueKeys = ['min', 'max', 'now', 'text'];
16
- exports.accessiblityValueKeys = accessiblityValueKeys;
24
+ const accessibilityStateKeys = exports.accessibilityStateKeys = ['disabled', 'selected', 'checked', 'busy', 'expanded'];
25
+ const accessiblityValueKeys = exports.accessiblityValueKeys = ['min', 'max', 'now', 'text'];
17
26
  function isHiddenFromAccessibility(element, {
18
27
  cache
19
28
  } = {}) {
@@ -36,14 +45,18 @@ function isHiddenFromAccessibility(element, {
36
45
  }
37
46
 
38
47
  /** RTL-compatitibility alias for `isHiddenFromAccessibility` */
39
- const isInaccessible = isHiddenFromAccessibility;
40
- exports.isInaccessible = isInaccessible;
48
+ const isInaccessible = exports.isInaccessible = isHiddenFromAccessibility;
41
49
  function isSubtreeInaccessible(element) {
42
50
  // Null props can happen for React.Fragments
43
51
  if (element.props == null) {
44
52
  return false;
45
53
  }
46
54
 
55
+ // See: https://reactnative.dev/docs/accessibility#aria-hidden
56
+ if (element.props['aria-hidden']) {
57
+ return true;
58
+ }
59
+
47
60
  // iOS: accessibilityElementsHidden
48
61
  // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios
49
62
  if (element.props.accessibilityElementsHidden) {
@@ -60,10 +73,10 @@ function isSubtreeInaccessible(element) {
60
73
  const flatStyle = _reactNative.StyleSheet.flatten(element.props.style) ?? {};
61
74
  if (flatStyle.display === 'none') return true;
62
75
 
63
- // iOS: accessibilityViewIsModal
76
+ // iOS: accessibilityViewIsModal or aria-modal
64
77
  // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios
65
78
  const hostSiblings = (0, _componentTree.getHostSiblings)(element);
66
- if (hostSiblings.some(sibling => sibling.props.accessibilityViewIsModal)) {
79
+ if (hostSiblings.some(sibling => getAccessibilityViewIsModal(sibling))) {
67
80
  return true;
68
81
  }
69
82
  return false;
@@ -78,4 +91,91 @@ function isAccessibilityElement(element) {
78
91
  const hostComponentNames = (0, _hostComponentNames.getHostComponentNames)();
79
92
  return element?.type === hostComponentNames?.text || element?.type === hostComponentNames?.textInput || element?.type === hostComponentNames?.switch;
80
93
  }
94
+ function getAccessibilityRole(element) {
95
+ return element.props.role ?? element.props.accessibilityRole;
96
+ }
97
+ function getAccessibilityViewIsModal(element) {
98
+ return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;
99
+ }
100
+ function getAccessibilityLabel(element) {
101
+ return element.props['aria-label'] ?? element.props.accessibilityLabel;
102
+ }
103
+ function getAccessibilityLabelledBy(element) {
104
+ return element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
105
+ }
106
+ function getAccessibilityState(element) {
107
+ const {
108
+ accessibilityState,
109
+ 'aria-busy': ariaBusy,
110
+ 'aria-checked': ariaChecked,
111
+ 'aria-disabled': ariaDisabled,
112
+ 'aria-expanded': ariaExpanded,
113
+ 'aria-selected': ariaSelected
114
+ } = element.props;
115
+ const hasAnyAccessibilityStateProps = accessibilityState != null || ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null;
116
+ if (!hasAnyAccessibilityStateProps) {
117
+ return undefined;
118
+ }
119
+ return {
120
+ busy: ariaBusy ?? accessibilityState?.busy,
121
+ checked: ariaChecked ?? accessibilityState?.checked,
122
+ disabled: ariaDisabled ?? accessibilityState?.disabled,
123
+ expanded: ariaExpanded ?? accessibilityState?.expanded,
124
+ selected: ariaSelected ?? accessibilityState?.selected
125
+ };
126
+ }
127
+ function getAccessibilityCheckedState(element) {
128
+ const {
129
+ accessibilityState,
130
+ 'aria-checked': ariaChecked
131
+ } = element.props;
132
+ return ariaChecked ?? accessibilityState?.checked;
133
+ }
134
+ function getAccessibilityValue(element) {
135
+ const {
136
+ accessibilityValue,
137
+ 'aria-valuemax': ariaValueMax,
138
+ 'aria-valuemin': ariaValueMin,
139
+ 'aria-valuenow': ariaValueNow,
140
+ 'aria-valuetext': ariaValueText
141
+ } = element.props;
142
+ const hasAnyAccessibilityValueProps = accessibilityValue != null || ariaValueMax != null || ariaValueMin != null || ariaValueNow != null || ariaValueText != null;
143
+ if (!hasAnyAccessibilityValueProps) {
144
+ return undefined;
145
+ }
146
+ return {
147
+ max: ariaValueMax ?? accessibilityValue?.max,
148
+ min: ariaValueMin ?? accessibilityValue?.min,
149
+ now: ariaValueNow ?? accessibilityValue?.now,
150
+ text: ariaValueText ?? accessibilityValue?.text
151
+ };
152
+ }
153
+ function isElementBusy(element) {
154
+ const {
155
+ accessibilityState,
156
+ 'aria-busy': ariaBusy
157
+ } = element.props;
158
+ return ariaBusy ?? accessibilityState?.busy ?? false;
159
+ }
160
+ function isElementCollapsed(element) {
161
+ const {
162
+ accessibilityState,
163
+ 'aria-expanded': ariaExpanded
164
+ } = element.props;
165
+ return (ariaExpanded ?? accessibilityState?.expanded) === false;
166
+ }
167
+ function isElementExpanded(element) {
168
+ const {
169
+ accessibilityState,
170
+ 'aria-expanded': ariaExpanded
171
+ } = element.props;
172
+ return ariaExpanded ?? accessibilityState?.expanded ?? false;
173
+ }
174
+ function isElementSelected(element) {
175
+ const {
176
+ accessibilityState,
177
+ 'aria-selected': ariaSelected
178
+ } = element.props;
179
+ return ariaSelected ?? accessibilityState?.selected ?? false;
180
+ }
81
181
  //# sourceMappingURL=accessiblity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessiblity.js","names":["_reactNative","require","_componentTree","_hostComponentNames","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal","isAccessibilityElement","accessible","hostComponentNames","getHostComponentNames","type","text","textInput","switch"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import {\n AccessibilityState,\n AccessibilityValue,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\nimport { getHostComponentNames } from './host-component-names';\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 accessiblityValueKeys: (keyof AccessibilityValue)[] = [\n 'min',\n 'max',\n 'now',\n 'text',\n];\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-compatitibility 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 // 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\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => sibling.props.accessibilityViewIsModal)) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(\n element: ReactTestInstance | null\n): boolean {\n if (element == null) {\n return false;\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"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAMO,MAAMG,sBAAoD,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAACC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA;AAEK,MAAME,qBAAmD,GAAG,CACjE,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,CACP;AAACD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAEK,SAASC,yBAAyBA,CACvCC,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAA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AEA,OAAO,KAAK;AACd;AAEO,SAASC,sBAAsBA,CACpCvB,OAAiC,EACxB;EACT,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,KAAK;EACd;EAEA,IAAIA,OAAO,CAACU,KAAK,CAACc,UAAU,KAAKnB,SAAS,EAAE;IAC1C,OAAOL,OAAO,CAACU,KAAK,CAACc,UAAU;EACjC;EAEA,MAAMC,kBAAkB,GAAG,IAAAC,yCAAqB,EAAC,CAAC;EAClD,OACE1B,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEG,IAAI,IAC1C5B,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEI,SAAS,IAC/C7B,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEK,MAAM;AAEhD"}
1
+ {"version":3,"file":"accessiblity.js","names":["_reactNative","require","_componentTree","_hostComponentNames","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","getAccessibilityViewIsModal","isAccessibilityElement","accessible","hostComponentNames","getHostComponentNames","type","text","textInput","switch","getAccessibilityRole","role","accessibilityRole","accessibilityViewIsModal","getAccessibilityLabel","accessibilityLabel","getAccessibilityLabelledBy","accessibilityLabelledBy","getAccessibilityState","accessibilityState","ariaBusy","ariaChecked","ariaDisabled","ariaExpanded","ariaSelected","hasAnyAccessibilityStateProps","busy","checked","disabled","expanded","selected","getAccessibilityCheckedState","getAccessibilityValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","hasAnyAccessibilityValueProps","max","min","now","isElementBusy","isElementCollapsed","isElementExpanded","isElementSelected"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import {\n AccessibilityState,\n AccessibilityValue,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\nimport { getHostComponentNames } from './host-component-names';\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 accessiblityValueKeys: (keyof AccessibilityValue)[] = [\n 'min',\n 'max',\n 'now',\n 'text',\n];\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-compatitibility 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) => getAccessibilityViewIsModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(\n element: ReactTestInstance | null\n): boolean {\n if (element == null) {\n return false;\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\nexport function getAccessibilityRole(\n element: ReactTestInstance\n): string | undefined {\n return element.props.role ?? element.props.accessibilityRole;\n}\n\nexport function getAccessibilityViewIsModal(element: ReactTestInstance) {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function getAccessibilityLabel(\n element: ReactTestInstance\n): string | undefined {\n return element.props['aria-label'] ?? element.props.accessibilityLabel;\n}\n\nexport function getAccessibilityLabelledBy(\n element: ReactTestInstance\n): string | undefined {\n return (\n element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy\n );\n}\n\nexport function getAccessibilityState(\n element: ReactTestInstance\n): AccessibilityState | undefined {\n const {\n accessibilityState,\n 'aria-busy': ariaBusy,\n 'aria-checked': ariaChecked,\n 'aria-disabled': ariaDisabled,\n 'aria-expanded': ariaExpanded,\n 'aria-selected': ariaSelected,\n } = element.props;\n\n const hasAnyAccessibilityStateProps =\n accessibilityState != null ||\n ariaBusy != null ||\n ariaChecked != null ||\n ariaDisabled != null ||\n ariaExpanded != null ||\n ariaSelected != null;\n\n if (!hasAnyAccessibilityStateProps) {\n return undefined;\n }\n\n return {\n busy: ariaBusy ?? accessibilityState?.busy,\n checked: ariaChecked ?? accessibilityState?.checked,\n disabled: ariaDisabled ?? accessibilityState?.disabled,\n expanded: ariaExpanded ?? accessibilityState?.expanded,\n selected: ariaSelected ?? accessibilityState?.selected,\n };\n}\n\nexport function getAccessibilityCheckedState(\n element: ReactTestInstance\n): AccessibilityState['checked'] {\n const { accessibilityState, 'aria-checked': ariaChecked } = element.props;\n return ariaChecked ?? accessibilityState?.checked;\n}\n\nexport function getAccessibilityValue(\n element: ReactTestInstance\n): AccessibilityValue | undefined {\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 const hasAnyAccessibilityValueProps =\n accessibilityValue != null ||\n ariaValueMax != null ||\n ariaValueMin != null ||\n ariaValueNow != null ||\n ariaValueText != null;\n\n if (!hasAnyAccessibilityValueProps) {\n return undefined;\n }\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 isElementBusy(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['busy']> {\n const { accessibilityState, 'aria-busy': ariaBusy } = element.props;\n return ariaBusy ?? accessibilityState?.busy ?? false;\n}\n\nexport function isElementCollapsed(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return (ariaExpanded ?? accessibilityState?.expanded) === false;\n}\n\nexport function isElementExpanded(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return ariaExpanded ?? accessibilityState?.expanded ?? false;\n}\n\nexport function isElementSelected(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['selected']> {\n const { accessibilityState, 'aria-selected': ariaSelected } = element.props;\n return ariaSelected ?? accessibilityState?.selected ?? false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAMO,MAAMG,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CACl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AC,GAAG7C,OAAO,CAACU,KAAK;EAC3E,OAAOmC,YAAY,IAAIL,kBAAkB,EAAEW,QAAQ,IAAI,KAAK;AAC9D"}
@@ -33,3 +33,10 @@ export declare function getHostSelves(element: ReactTestInstance | null): HostTe
33
33
  * @param element The element start traversing from.
34
34
  */
35
35
  export declare function getHostSiblings(element: ReactTestInstance | null): HostTestInstance[];
36
+ /**
37
+ * Returns the unsafe root element of the tree (probably composite).
38
+ *
39
+ * @param element The element start traversing from.
40
+ * @returns The root element of the tree (host or composite).
41
+ */
42
+ export declare function getUnsafeRootElement(element: ReactTestInstance | null): ReactTestInstance | null;
@@ -7,6 +7,7 @@ exports.getHostChildren = getHostChildren;
7
7
  exports.getHostParent = getHostParent;
8
8
  exports.getHostSelves = getHostSelves;
9
9
  exports.getHostSiblings = getHostSiblings;
10
+ exports.getUnsafeRootElement = getUnsafeRootElement;
10
11
  exports.isHostElement = isHostElement;
11
12
  /**
12
13
  * ReactTestInstance referring to host element.
@@ -80,4 +81,21 @@ function getHostSiblings(element) {
80
81
  const hostSelves = getHostSelves(element);
81
82
  return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
82
83
  }
84
+
85
+ /**
86
+ * Returns the unsafe root element of the tree (probably composite).
87
+ *
88
+ * @param element The element start traversing from.
89
+ * @returns The root element of the tree (host or composite).
90
+ */
91
+ function getUnsafeRootElement(element) {
92
+ if (element == null) {
93
+ return null;
94
+ }
95
+ let current = element;
96
+ while (current.parent) {
97
+ current = current.parent;
98
+ }
99
+ return current;
100
+ }
83
101
  //# sourceMappingURL=component-tree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component-tree.js","names":["isHostElement","element","type","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';\n\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(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return typeof element?.type === 'string';\n}\n\n/**\n * Returns first host ancestor for given element.\n * @param element The element start traversing from.\n */\nexport function getHostParent(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): HostTestInstance[] {\n const hostParent = getHostParent(element);\n const hostSelves = getHostSelves(element);\n return getHostChildren(hostParent).filter(\n (sibling) => !hostSelves.includes(sibling)\n );\n}\n"],"mappings":";;;;;;;;;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAC3BC,OAAkC,EACL;EAC7B,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AAC1C;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAC3BF,OAAiC,EACR;EACzB,IAAIA,OAAO,IAAI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Element","element","type","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes","getUnsafeRootElement"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\n\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(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return typeof element?.type === 'string';\n}\n\n/**\n * Returns first host ancestor for given element.\n * @param element The element start traversing from.\n */\nexport function getHostParent(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): 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(\n element: ReactTestInstance | null\n): HostTestInstance[] {\n const hostParent = getHostParent(element);\n const hostSelves = getHostSelves(element);\n return getHostChildren(hostParent).filter(\n (sibling) => !hostSelves.includes(sibling)\n );\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 | null) {\n if (element == null) {\n return null;\n }\n\n let current = element;\n while (current.parent) {\n current = current.parent;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAC3BC,OAAkC,EACL;EAC7B,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AAC1C;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAC3BF,OAAiC,EACR;EACzB,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIG,OAAO,GAAGH,OAAO,CAACI,MAAM;EAC5B,OAAOD,OAAO,EAAE;IACd,IAAIJ,aAAa,CAACI,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,CAC7BL,OAAiC,EACb;EACpB,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,EAAE;EACX;EAEA,MAAMM,YAAgC,GAAG,EAAE;EAE3CN,OAAO,CAACO,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAK;IAClC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B;IACF;IAEA,IAAIV,aAAa,CAACU,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,CAC3BX,OAAiC,EACb;EACpB,OAAOD,aAAa,CAACC,OAAO,CAAC,GAAG,CAACA,OAAO,CAAC,GAAGK,eAAe,CAACL,OAAO,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACO,SAASY,eAAeA,CAC7BZ,OAAiC,EACb;EACpB,MAAMa,UAAU,GAAGX,aAAa,CAACF,OAAO,CAAC;EACzC,MAAMc,UAAU,GAAGH,aAAa,CAACX,OAAO,CAAC;EACzC,OAAOK,eAAe,CAACQ,UAAU,CAAC,CAACE,MAAM,CACtCC,OAAO,IAAK,CAACF,UAAU,CAACG,QAAQ,CAACD,OAAO,CAC3C,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,oBAAoBA,CAAClB,OAAiC,EAAE;EACtE,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIG,OAAO,GAAGH,OAAO;EACrB,OAAOG,OAAO,CAACC,MAAM,EAAE;IACrBD,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAOD,OAAO;AAChB"}
@@ -1,5 +1,4 @@
1
- import { MapPropsFunction } from './format';
2
1
  /**
3
2
  * Preserve props that are helpful in diagnosing test failures, while stripping rest
4
3
  */
5
- export declare const defaultMapProps: MapPropsFunction;
4
+ export declare function defaultMapProps(props: Record<string, unknown>): Record<string, unknown>;
@@ -3,20 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defaultMapProps = void 0;
6
+ exports.defaultMapProps = defaultMapProps;
7
7
  var _reactNative = require("react-native");
8
- const propsToDisplay = ['testID', 'nativeID', 'accessibilityElementsHidden', 'accessibilityViewIsModal', 'importantForAccessibility', 'accessibilityRole', 'accessibilityLabel', 'accessibilityLabelledBy', 'accessibilityHint', 'placeholder', 'value', 'defaultValue', 'title'];
8
+ const propsToDisplay = ['accessible', 'accessibilityElementsHidden', 'accessibilityHint', 'accessibilityLabel', 'accessibilityLabelledBy', 'accessibilityRole', 'accessibilityViewIsModal', 'aria-busy', 'aria-checked', 'aria-disabled', 'aria-expanded', 'aria-hidden', 'aria-label', 'aria-labelledby', 'aria-modal', 'aria-selected', 'aria-valuemax', 'aria-valuemin', 'aria-valuenow', 'aria-valuetext', 'defaultValue', 'importantForAccessibility', 'nativeID', 'placeholder', 'role', 'testID', 'title', 'value'];
9
9
 
10
10
  /**
11
11
  * Preserve props that are helpful in diagnosing test failures, while stripping rest
12
12
  */
13
- const defaultMapProps = props => {
13
+ function defaultMapProps(props) {
14
14
  const result = {};
15
15
  const styles = _reactNative.StyleSheet.flatten(props.style);
16
- if (styles?.display === 'none') {
17
- result.style = {
18
- display: 'none'
19
- };
16
+ const styleToDisplay = extractStyle(styles);
17
+ if (styleToDisplay !== undefined) {
18
+ result.style = styleToDisplay;
20
19
  }
21
20
  const accessibilityState = removeUndefinedKeys(props.accessibilityState);
22
21
  if (accessibilityState !== undefined) {
@@ -32,8 +31,7 @@ const defaultMapProps = props => {
32
31
  }
33
32
  });
34
33
  return result;
35
- };
36
- exports.defaultMapProps = defaultMapProps;
34
+ }
37
35
  function isObject(value) {
38
36
  return typeof value === 'object' && value !== null && !Array.isArray(value);
39
37
  }
@@ -41,17 +39,28 @@ function removeUndefinedKeys(prop) {
41
39
  if (!isObject(prop)) {
42
40
  return prop;
43
41
  }
42
+ let hasKeys = false;
44
43
  const result = {};
45
44
  Object.entries(prop).forEach(([key, value]) => {
46
45
  if (value !== undefined) {
47
46
  result[key] = value;
47
+ hasKeys = true;
48
48
  }
49
49
  });
50
-
51
- // If object does not have any props we will ignore it.
52
- if (Object.keys(result).length === 0) {
50
+ return hasKeys ? result : undefined;
51
+ }
52
+ function extractStyle(style) {
53
+ if (style == null) {
53
54
  return undefined;
54
55
  }
55
- return result;
56
+ const result = {};
57
+ if (style.display === 'none') {
58
+ result.display = 'none';
59
+ }
60
+ if (style.opacity === 0) {
61
+ result.opacity = 0;
62
+ }
63
+ const hasAnyKeys = Object.keys(result).length > 0;
64
+ return hasAnyKeys ? result : undefined;
56
65
  }
57
66
  //# sourceMappingURL=format-default.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-default.js","names":["_reactNative","require","propsToDisplay","defaultMapProps","props","result","styles","StyleSheet","flatten","style","display","accessibilityState","removeUndefinedKeys","undefined","accessibilityValue","forEach","propName","exports","isObject","value","Array","isArray","prop","Object","entries","key","keys","length"],"sources":["../../src/helpers/format-default.ts"],"sourcesContent":["import { StyleSheet, ViewStyle } from 'react-native';\nimport { MapPropsFunction } from './format';\n\nconst propsToDisplay = [\n 'testID',\n 'nativeID',\n 'accessibilityElementsHidden',\n 'accessibilityViewIsModal',\n 'importantForAccessibility',\n 'accessibilityRole',\n 'accessibilityLabel',\n 'accessibilityLabelledBy',\n 'accessibilityHint',\n 'placeholder',\n 'value',\n 'defaultValue',\n 'title',\n];\n\n/**\n * Preserve props that are helpful in diagnosing test failures, while stripping rest\n */\nexport const defaultMapProps: MapPropsFunction = (props) => {\n const result: Record<string, unknown> = {};\n\n const styles = StyleSheet.flatten(props.style as ViewStyle);\n if (styles?.display === 'none') {\n result.style = { display: 'none' };\n }\n\n const accessibilityState = removeUndefinedKeys(props.accessibilityState);\n if (accessibilityState !== undefined) {\n result.accessibilityState = accessibilityState;\n }\n\n const accessibilityValue = removeUndefinedKeys(props.accessibilityValue);\n if (accessibilityValue !== undefined) {\n result.accessibilityValue = accessibilityValue;\n }\n\n propsToDisplay.forEach((propName) => {\n if (propName in props) {\n result[propName] = props[propName];\n }\n });\n\n return result;\n};\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction removeUndefinedKeys(prop: unknown) {\n if (!isObject(prop)) {\n return prop;\n }\n\n const result: Record<string, unknown> = {};\n Object.entries(prop).forEach(([key, value]) => {\n if (value !== undefined) {\n result[key] = value;\n }\n });\n\n // If object does not have any props we will ignore it.\n if (Object.keys(result).length === 0) {\n return undefined;\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAAA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K,CAAC;AAC7E;AAEA,SAASP,mBAAmBA,CAACU,IAAa,EAAE;EAC1C,IAAI,CAACJ,QAAQ,CAACI,IAAI,CAAC,EAAE;IACnB,OAAOA,IAAI;EACb;EAEA,MAAMjB,MAA+B,GAAG,CAAC,CAAC;EAC1CkB,MAAM,CAACC,OAAO,CAACF,IAAI,CAAC,CAACP,OAAO,CAAC,CAAC,CAACU,GAAG,EAAEN,KAAK,CAAC,KAAK;IAC7C,IAAIA,KAAK,KAAKN,SAAS,EAAE;MACvBR,MAAM,CAACoB,GAAG,CAAC,GAAGN,KAAK;IACrB;EACF,CAAC,CAAC;;EAEF;EACA,IAAII,MAAM,CAACG,IAAI,CAACrB,MAAM,CAAC,CAACsB,MAAM,KAAK,CAAC,EAAE;IACpC,OAAOd,SAAS;EAClB;EAEA,OAAOR,MAAM;AACf"}
1
+ {"version":3,"file":"format-default.js","names":["_reactNative","require","propsToDisplay","defaultMapProps","props","result","styles","StyleSheet","flatten","style","styleToDisplay","extractStyle","undefined","accessibilityState","removeUndefinedKeys","accessibilityValue","forEach","propName","isObject","value","Array","isArray","prop","hasKeys","Object","entries","key","display","opacity","hasAnyKeys","keys","length"],"sources":["../../src/helpers/format-default.ts"],"sourcesContent":["import { StyleSheet, ViewStyle } from 'react-native';\n\nconst propsToDisplay = [\n 'accessible',\n 'accessibilityElementsHidden',\n 'accessibilityHint',\n 'accessibilityLabel',\n 'accessibilityLabelledBy',\n 'accessibilityRole',\n 'accessibilityViewIsModal',\n 'aria-busy',\n 'aria-checked',\n 'aria-disabled',\n 'aria-expanded',\n 'aria-hidden',\n 'aria-label',\n 'aria-labelledby',\n 'aria-modal',\n 'aria-selected',\n 'aria-valuemax',\n 'aria-valuemin',\n 'aria-valuenow',\n 'aria-valuetext',\n 'defaultValue',\n 'importantForAccessibility',\n 'nativeID',\n 'placeholder',\n 'role',\n 'testID',\n 'title',\n 'value',\n] as const;\n\n/**\n * Preserve props that are helpful in diagnosing test failures, while stripping rest\n */\nexport function defaultMapProps(\n props: Record<string, unknown>\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n const styles = StyleSheet.flatten(props.style as ViewStyle);\n const styleToDisplay = extractStyle(styles);\n if (styleToDisplay !== undefined) {\n result.style = styleToDisplay;\n }\n\n const accessibilityState = removeUndefinedKeys(props.accessibilityState);\n if (accessibilityState !== undefined) {\n result.accessibilityState = accessibilityState;\n }\n\n const accessibilityValue = removeUndefinedKeys(props.accessibilityValue);\n if (accessibilityValue !== undefined) {\n result.accessibilityValue = accessibilityValue;\n }\n\n propsToDisplay.forEach((propName) => {\n if (propName in props) {\n result[propName] = props[propName];\n }\n });\n\n return result;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction removeUndefinedKeys(prop: unknown) {\n if (!isObject(prop)) {\n return prop;\n }\n\n let hasKeys = false;\n const result: Record<string, unknown> = {};\n Object.entries(prop).forEach(([key, value]) => {\n if (value !== undefined) {\n result[key] = value;\n hasKeys = true;\n }\n });\n\n return hasKeys ? result : undefined;\n}\n\nfunction extractStyle(style: ViewStyle | undefined) {\n if (style == null) {\n return undefined;\n }\n\n const result: Record<string, unknown> = {};\n if (style.display === 'none') {\n result.display = 'none';\n }\n\n if (style.opacity === 0) {\n result.opacity = 0;\n }\n\n const hasAnyKeys = Object.keys(result).length > 0;\n return hasAnyKeys ? result : undefined;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,cAAc,GAAG,CACrB,YAAY,EACZ,6BAA6B,EAC7B,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACX,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,2BAA2B,E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,CAAC,CAAC;EAC1CmB,MAAM,CAACC,OAAO,CAACH,IAAI,CAAC,CAACN,OAAO,CAAC,CAAC,CAACU,GAAG,EAAEP,KAAK,CAAC,KAAK;IAC7C,IAAIA,KAAK,KAAKP,SAAS,EAAE;MACvBP,MAAM,CAACqB,GAAG,CAAC,GAAGP,KAAK;MACnBI,OAAO,GAAG,IAAI;IAChB;EACF,CAAC,CAAC;EAEF,OAAOA,OAAO,GAAGlB,MAAM,GAAGO,SAAS;AACrC;AAEA,SAASD,YAAYA,CAACF,KAA4B,EAAE;EAClD,IAAIA,KAAK,IAAI,IAAI,EAAE;IACjB,OAAOG,SAAS;EAClB;EAEA,MAAMP,MAA+B,GAAG,CAAC,CAAC;EAC1C,IAAII,KAAK,CAACkB,OAAO,KAAK,MAAM,EAAE;IAC5BtB,MAAM,CAACsB,OAAO,GAAG,MAAM;EACzB;EAEA,IAAIlB,KAAK,CAACmB,OAAO,KAAK,CAAC,EAAE;IACvBvB,MAAM,CAACuB,OAAO,GAAG,CAAC;EACpB;EAEA,MAAMC,UAAU,GAAGL,MAAM,CAACM,IAAI,CAACzB,MAAM,CAAC,CAAC0B,MAAM,GAAG,CAAC;EACjD,OAAOF,UAAU,GAAGxB,MAAM,GAAGO,SAAS;AACxC"}
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _prettyFormat = _interopRequireWildcard(require("pretty-format"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
8
+ 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); }
9
+ 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 && Object.prototype.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; }
10
10
  const format = (input, options = {}) => (0, _prettyFormat.default)(input, {
11
11
  plugins: [getCustomPlugin(options.mapProps), _prettyFormat.plugins.ReactElement],
12
- highlight: shouldHighlight(),
12
+ highlight: true,
13
13
  printBasicPrototype: false
14
14
  });
15
15
  const getCustomPlugin = mapProps => {
@@ -27,9 +27,5 @@ const getCustomPlugin = mapProps => {
27
27
  }
28
28
  };
29
29
  };
30
- function shouldHighlight() {
31
- return process?.env?.COLORS !== 'false';
32
- }
33
- var _default = format;
34
- exports.default = _default;
30
+ var _default = exports.default = format;
35
31
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","names":["_prettyFormat","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","format","input","options","prettyFormat","plugins","getCustomPlugin","mapProps","ReactElement","highlight","shouldHighlight","printBasicPrototype","test","val","ReactTestComponent","serialize","config","indentation","depth","refs","printer","newVal","props","process","env","COLORS","_default","exports"],"sources":["../../src/helpers/format.ts"],"sourcesContent":["import type { ReactTestRendererJSON } from 'react-test-renderer';\nimport prettyFormat, { NewPlugin, plugins } from 'pretty-format';\n\nexport type MapPropsFunction = (\n props: Record<string, unknown>,\n node: ReactTestRendererJSON\n) => Record<string, unknown>;\n\nexport type FormatOptions = {\n mapProps?: MapPropsFunction;\n};\n\nconst format = (\n input: ReactTestRendererJSON | ReactTestRendererJSON[],\n options: FormatOptions = {}\n) =>\n prettyFormat(input, {\n plugins: [getCustomPlugin(options.mapProps), plugins.ReactElement],\n highlight: shouldHighlight(),\n printBasicPrototype: false,\n });\n\nconst getCustomPlugin = (mapProps?: MapPropsFunction): NewPlugin => {\n return {\n test: (val) => plugins.ReactTestComponent.test(val),\n serialize: (val, config, indentation, depth, refs, printer) => {\n let newVal = val;\n if (mapProps && val.props) {\n newVal = { ...val, props: mapProps(val.props, val) };\n }\n return plugins.ReactTestComponent.serialize(\n newVal,\n config,\n indentation,\n depth,\n refs,\n printer\n );\n },\n };\n};\n\nfunction shouldHighlight() {\n return process?.env?.COLORS !== 'false';\n}\n\nexport default format;\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAiE,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WA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ACnDE,SAAS,EAAEA,CAACF,GAAG,EAAEG,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,KAAK;MAC7D,IAAIC,MAAM,GAAGR,GAAG;MAChB,IAAIN,QAAQ,IAAIM,GAAG,CAACS,KAAK,EAAE;QACzBD,MAAM,GAAG;UAAE,GAAGR,GAAG;UAAES,KAAK,EAAEf,QAAQ,CAACM,GAAG,CAACS,KAAK,EAAET,GAAG;QAAE,CAAC;MACtD;MACA,OAAOR,qBAAO,CAACS,kBAAkB,CAACC,SAAS,CACzCM,MAAM,EACNL,MAAM,EACNC,WAAW,EACXC,KAAK,EACLC,IAAI,EACJC,OACF,CAAC;IACH;EACF,CAAC;AACH,CAAC;AAED,SAASV,eAAeA,CAAA,EAAG;EACzB,OAAOa,OAAO,EAAEC,GAAG,EAAEC,MAAM,KAAK,OAAO;AACzC;AAAC,IAAAC,QAAA,GAEczB,MAAM;AAAA0B,OAAA,CAAAzC,OAAA,GAAAwC,QAAA"}
1
+ {"version":3,"file":"format.js","names":["_prettyFormat","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","format","input","options","prettyFormat","plugins","getCustomPlugin","mapProps","ReactElement","highlight","printBasicPrototype","test","val","ReactTestComponent","serialize","config","indentation","depth","refs","printer","newVal","props","_default","exports"],"sources":["../../src/helpers/format.ts"],"sourcesContent":["import type { ReactTestRendererJSON } from 'react-test-renderer';\nimport prettyFormat, { NewPlugin, plugins } from 'pretty-format';\n\nexport type MapPropsFunction = (\n props: Record<string, unknown>,\n node: ReactTestRendererJSON\n) => Record<string, unknown>;\n\nexport type FormatOptions = {\n mapProps?: MapPropsFunction;\n};\n\nconst format = (\n input: ReactTestRendererJSON | ReactTestRendererJSON[],\n options: FormatOptions = {}\n) =>\n prettyFormat(input, {\n plugins: [getCustomPlugin(options.mapProps), plugins.ReactElement],\n highlight: true,\n printBasicPrototype: false,\n });\n\nconst getCustomPlugin = (mapProps?: MapPropsFunction): NewPlugin => {\n return {\n test: (val) => plugins.ReactTestComponent.test(val),\n serialize: (val, config, indentation, depth, refs, printer) => {\n let newVal = val;\n if (mapProps && val.props) {\n newVal = { ...val, props: mapProps(val.props, val) };\n }\n return plugins.ReactTestComponent.serialize(\n newVal,\n config,\n indentation,\n depth,\n refs,\n printer\n );\n },\n };\n};\n\nexport default format;\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAiE,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,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAWjE,MAAMY,MAAM,GAAGA,CACbC,KAAsD,EACtDC,OAAsB,GAAG,CAAC,CAAC,KAE3B,IAAAC,qBAAY,EAACF,KAAK,EAAE;EAClBG,OAAO,EAAE,CAACC,eAAe,CAACH,OAAO,CAACI,QAAQ,CAAC,EAAEF,qBAAO,CAACG,YAAY,CAAC;EAClEC,SAAS,EAAE,IAAI;EACfC,mBAAmB,EAAE;AACvB,CAAC,CAAC;AAEJ,MAAMJ,eAAe,GAAIC,QAA2B,IAAgB;EAClE,OAAO;IACLI,IAAI,EAAGC,GAAG,IAAKP,qBAAO,CAACQ,kBAAkB,CAACF,IAAI,CAACC,GAAG,CAAC;IACnDE,SAAS,EAAEA,CAACF,GAAG,EAAEG,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,KAAK;MAC7D,IAAIC,MAAM,GAAGR,GAAG;MAChB,IAAIL,QAAQ,IAAIK,GAAG,CAACS,KAAK,EAAE;QACzBD,MAAM,GAAG;UAAE,GAAGR,GAAG;UAAES,KAAK,EAAEd,QAAQ,CAACK,GAAG,CAACS,KAAK,EAAET,GAAG;QAAE,CAAC;MACtD;MACA,OAAOP,qBAAO,CAACQ,kBAAkB,CAACC,SAAS,CACzCM,MAAM,EACNL,MAAM,EACNC,WAAW,EACXC,KAAK,EACLC,IAAI,EACJC,OACF,CAAC;IACH;EACF,CAAC;AACH,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAArC,OAAA,GAEae,MAAM"}
@@ -13,3 +13,13 @@ export declare function isHostText(element?: ReactTestInstance | null): element
13
13
  * @param element The element to check.
14
14
  */
15
15
  export declare function isHostTextInput(element?: ReactTestInstance | null): element is HostTestInstance;
16
+ /**
17
+ * Checks if the given element is a host ScrollView.
18
+ * @param element The element to check.
19
+ */
20
+ export declare function isHostScrollView(element?: ReactTestInstance | null): element is HostTestInstance;
21
+ /**
22
+ * Checks if the given element is a host Modal.
23
+ * @param element The element to check.
24
+ */
25
+ export declare function isHostModal(element?: ReactTestInstance | null): element is HostTestInstance;