@testing-library/react-native 12.2.2 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/build/config.d.ts +1 -0
  2. package/build/config.js.map +1 -1
  3. package/build/fireEvent.js +2 -1
  4. package/build/fireEvent.js.map +1 -1
  5. package/build/helpers/accessiblity.d.ts +7 -0
  6. package/build/helpers/accessiblity.js +73 -2
  7. package/build/helpers/accessiblity.js.map +1 -1
  8. package/build/helpers/component-tree.d.ts +7 -0
  9. package/build/helpers/component-tree.js +18 -0
  10. package/build/helpers/component-tree.js.map +1 -1
  11. package/build/helpers/format-default.d.ts +1 -2
  12. package/build/helpers/format-default.js +22 -13
  13. package/build/helpers/format-default.js.map +1 -1
  14. package/build/helpers/format.js +1 -4
  15. package/build/helpers/format.js.map +1 -1
  16. package/build/helpers/host-component-names.d.ts +5 -0
  17. package/build/helpers/host-component-names.js +13 -1
  18. package/build/helpers/host-component-names.js.map +1 -1
  19. package/build/helpers/matchers/accessibilityState.js +3 -3
  20. package/build/helpers/matchers/accessibilityState.js.map +1 -1
  21. package/build/helpers/matchers/accessibilityValue.js +3 -2
  22. package/build/helpers/matchers/accessibilityValue.js.map +1 -1
  23. package/build/helpers/matchers/matchLabelText.d.ts +1 -1
  24. package/build/helpers/matchers/matchLabelText.js +5 -8
  25. package/build/helpers/matchers/matchLabelText.js.map +1 -1
  26. package/build/helpers/matchers/matchTextContent.js +2 -2
  27. package/build/helpers/matchers/matchTextContent.js.map +1 -1
  28. package/build/helpers/{getTextContent.js → text-content.js} +1 -1
  29. package/build/helpers/text-content.js.map +1 -0
  30. package/build/helpers/text-input.d.ts +3 -0
  31. package/build/helpers/text-input.js +21 -0
  32. package/build/helpers/text-input.js.map +1 -0
  33. package/build/matchers/extend-expect.d.js +2 -0
  34. package/build/matchers/extend-expect.d.js.map +1 -0
  35. package/build/matchers/extend-expect.d.ts +2 -0
  36. package/build/matchers/extend-expect.js +26 -0
  37. package/build/matchers/extend-expect.js.map +1 -0
  38. package/build/matchers/index.d.ts +9 -0
  39. package/build/matchers/index.js +75 -0
  40. package/build/matchers/index.js.map +1 -0
  41. package/build/matchers/to-be-checked.d.ts +6 -0
  42. package/build/matchers/to-be-checked.js +31 -0
  43. package/build/matchers/to-be-checked.js.map +1 -0
  44. package/build/matchers/to-be-disabled.d.ts +10 -0
  45. package/build/matchers/to-be-disabled.js +52 -0
  46. package/build/matchers/to-be-disabled.js.map +1 -0
  47. package/build/matchers/to-be-empty-element.d.ts +6 -0
  48. package/build/matchers/to-be-empty-element.js +20 -0
  49. package/build/matchers/to-be-empty-element.js.map +1 -0
  50. package/build/matchers/to-be-on-the-screen.d.ts +6 -0
  51. package/build/matchers/to-be-on-the-screen.js +29 -0
  52. package/build/matchers/to-be-on-the-screen.js.map +1 -0
  53. package/build/matchers/to-be-partially-checked.d.ts +6 -0
  54. package/build/matchers/to-be-partially-checked.js +28 -0
  55. package/build/matchers/to-be-partially-checked.js.map +1 -0
  56. package/build/matchers/to-be-visible.d.ts +6 -0
  57. package/build/matchers/to-be-visible.js +56 -0
  58. package/build/matchers/to-be-visible.js.map +1 -0
  59. package/build/matchers/to-have-display-value.d.ts +7 -0
  60. package/build/matchers/to-have-display-value.js +26 -0
  61. package/build/matchers/to-have-display-value.js.map +1 -0
  62. package/build/matchers/to-have-prop.d.ts +6 -0
  63. package/build/matchers/to-have-prop.js +35 -0
  64. package/build/matchers/to-have-prop.js.map +1 -0
  65. package/build/matchers/to-have-text-content.d.ts +7 -0
  66. package/build/matchers/to-have-text-content.js +21 -0
  67. package/build/matchers/to-have-text-content.js.map +1 -0
  68. package/build/matchers/utils.d.ts +18 -0
  69. package/build/matchers/utils.js +90 -0
  70. package/build/matchers/utils.js.map +1 -0
  71. package/build/matches.d.ts +1 -1
  72. package/build/matches.js.map +1 -1
  73. package/build/queries/displayValue.js +4 -3
  74. package/build/queries/displayValue.js.map +1 -1
  75. package/build/queries/labelText.js +2 -2
  76. package/build/queries/labelText.js.map +1 -1
  77. package/build/queries/role.js +1 -1
  78. package/build/queries/role.js.map +1 -1
  79. package/build/render.d.ts +12 -48
  80. package/build/user-event/clear.js +2 -1
  81. package/build/user-event/clear.js.map +1 -1
  82. package/build/user-event/press/press.js +2 -1
  83. package/build/user-event/press/press.js.map +1 -1
  84. package/build/user-event/type/type.js +2 -1
  85. package/build/user-event/type/type.js.map +1 -1
  86. package/build/user-event/utils/index.d.ts +0 -1
  87. package/build/user-event/utils/index.js +0 -11
  88. package/build/user-event/utils/index.js.map +1 -1
  89. package/package.json +5 -21
  90. package/build/helpers/getTextContent.js.map +0 -1
  91. package/build/user-event/utils/host-components.d.ts +0 -2
  92. package/build/user-event/utils/host-components.js +0 -11
  93. package/build/user-event/utils/host-components.js.map +0 -1
  94. /package/build/helpers/{getTextContent.d.ts → text-content.d.ts} +0 -0
package/build/config.d.ts CHANGED
@@ -18,6 +18,7 @@ export type HostComponentNames = {
18
18
  text: string;
19
19
  textInput: string;
20
20
  switch: string;
21
+ modal: string;
21
22
  };
22
23
  export type InternalConfig = Config & {
23
24
  /** 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 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;;AA8BA,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;
@@ -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,mCAAe,EAACL,OAAO,CAAC;AAEhF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAA0B,EAC1BU,SAAiB,EACjBC,qBAAyC,EACzC;EACA,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC1C,OACEA,qBAAqB,EAAER,KAAK,CAACS,QAAQ,KAAK,KAAK,IAC/CJ,mCAAmC,CAACK,GAAG,CAACH,SAAS,CAAC;EAEtD;EAEA,IAC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,CAAC,KAAK,UAAU,EAAE;IAClD,OAAOV,OAAO,CAACG,KAAK,CAACO,SAAS,CAAC;EACjC;EAEA,OAAOQ,SAAS;AAClB;AAEA,SAASO,mBAAmBA,CAACf,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACgB,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEjB,SAAS,CAACkB,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE;;AAEA;;AAGA;;AAeA,SAASC,SAASA,CAChB7B,OAA0B,EAC1BU,SAAoB,EACpB,GAAGoB,IAAe,EAClB;EACA,MAAMT,OAAO,GAAGF,gBAAgB,CAACnB,OAAO,EAAEU,SAAS,CAAC;EACpD,IAAI,CAACW,OAAO,EAAE;IACZ;EACF;EAEA,IAAIU,WAAW;EACf,IAAAC,YAAG,EAAC,MAAM;IACRD,WAAW,GAAGV,OAAO,CAAC,GAAGS,IAAI,CAAC;EAChC,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB;AAEAF,SAAS,CAACI,KAAK,GAAG,CAACjC,OAA0B,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;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAA0B,EAC1BU,SAAiB,EACjBC,qBAAyC,EACzC;EACA,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC1C,OACE,IAAAC,8BAAmB,EAACD,qBAAqB,CAAC,IAC1CH,mCAAmC,CAACK,GAAG,CAACH,SAAS,CAAC;EAEtD;EAEA,IACEJ,iCAAiC,CAACO,GAAG,CAACH,SAAS,CAAC,IAChD,CAAC,IAAAI,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SAAS,CAAC;EACjC;EAEA,OAAOQ,SAAS;AAClB;AAEA,SAASO,mBAAmBA,CAACf,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACgB,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEjB,SAAS,CAACkB,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE;;AAEA;;AAGA;;AAeA,SAASC,SAASA,CAChB7B,OAA0B,EAC1BU,SAAoB,EACpB,GAAGoB,IAAe,EAClB;EACA,MAAMT,OAAO,GAAGF,gBAAgB,CAACnB,OAAO,EAAEU,SAAS,CAAC;EACpD,IAAI,CAACW,OAAO,EAAE;IACZ;EACF;EAEA,IAAIU,WAAW;EACf,IAAAC,YAAG,EAAC,MAAM;IACRD,WAAW,GAAGV,OAAO,CAAC,GAAGS,IAAI,CAAC;EAChC,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB;AAEAF,SAAS,CAACI,KAAK,GAAG,CAACjC,OAA0B,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"}
@@ -9,4 +9,11 @@ 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;
12
19
  export {};
@@ -4,6 +4,13 @@ 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;
8
15
  exports.isHiddenFromAccessibility = isHiddenFromAccessibility;
9
16
  exports.isInaccessible = void 0;
@@ -44,6 +51,11 @@ function isSubtreeInaccessible(element) {
44
51
  return false;
45
52
  }
46
53
 
54
+ // See: https://reactnative.dev/docs/accessibility#aria-hidden
55
+ if (element.props['aria-hidden']) {
56
+ return true;
57
+ }
58
+
47
59
  // iOS: accessibilityElementsHidden
48
60
  // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios
49
61
  if (element.props.accessibilityElementsHidden) {
@@ -60,10 +72,10 @@ function isSubtreeInaccessible(element) {
60
72
  const flatStyle = _reactNative.StyleSheet.flatten(element.props.style) ?? {};
61
73
  if (flatStyle.display === 'none') return true;
62
74
 
63
- // iOS: accessibilityViewIsModal
75
+ // iOS: accessibilityViewIsModal or aria-modal
64
76
  // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios
65
77
  const hostSiblings = (0, _componentTree.getHostSiblings)(element);
66
- if (hostSiblings.some(sibling => sibling.props.accessibilityViewIsModal)) {
78
+ if (hostSiblings.some(sibling => getAccessibilityViewIsModal(sibling))) {
67
79
  return true;
68
80
  }
69
81
  return false;
@@ -78,4 +90,63 @@ function isAccessibilityElement(element) {
78
90
  const hostComponentNames = (0, _hostComponentNames.getHostComponentNames)();
79
91
  return element?.type === hostComponentNames?.text || element?.type === hostComponentNames?.textInput || element?.type === hostComponentNames?.switch;
80
92
  }
93
+ function getAccessibilityRole(element) {
94
+ return element.props.role ?? element.props.accessibilityRole;
95
+ }
96
+ function getAccessibilityViewIsModal(element) {
97
+ return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;
98
+ }
99
+ function getAccessibilityLabel(element) {
100
+ return element.props['aria-label'] ?? element.props.accessibilityLabel;
101
+ }
102
+ function getAccessibilityLabelledBy(element) {
103
+ return element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
104
+ }
105
+ function getAccessibilityState(element) {
106
+ const {
107
+ accessibilityState,
108
+ 'aria-busy': ariaBusy,
109
+ 'aria-checked': ariaChecked,
110
+ 'aria-disabled': ariaDisabled,
111
+ 'aria-expanded': ariaExpanded,
112
+ 'aria-selected': ariaSelected
113
+ } = element.props;
114
+ const hasAnyAccessibilityStateProps = accessibilityState != null || ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null;
115
+ if (!hasAnyAccessibilityStateProps) {
116
+ return undefined;
117
+ }
118
+ return {
119
+ busy: ariaBusy ?? accessibilityState?.busy,
120
+ checked: ariaChecked ?? accessibilityState?.checked,
121
+ disabled: ariaDisabled ?? accessibilityState?.disabled,
122
+ expanded: ariaExpanded ?? accessibilityState?.expanded,
123
+ selected: ariaSelected ?? accessibilityState?.selected
124
+ };
125
+ }
126
+ function getAccessibilityCheckedState(element) {
127
+ const {
128
+ accessibilityState,
129
+ 'aria-checked': ariaChecked
130
+ } = element.props;
131
+ return ariaChecked ?? accessibilityState?.checked;
132
+ }
133
+ function getAccessibilityValue(element) {
134
+ const {
135
+ accessibilityValue,
136
+ 'aria-valuemax': ariaValueMax,
137
+ 'aria-valuemin': ariaValueMin,
138
+ 'aria-valuenow': ariaValueNow,
139
+ 'aria-valuetext': ariaValueText
140
+ } = element.props;
141
+ const hasAnyAccessibilityValueProps = accessibilityValue != null || ariaValueMax != null || ariaValueMin != null || ariaValueNow != null || ariaValueText != null;
142
+ if (!hasAnyAccessibilityValueProps) {
143
+ return undefined;
144
+ }
145
+ return {
146
+ max: ariaValueMax ?? accessibilityValue?.max,
147
+ min: ariaValueMin ?? accessibilityValue?.min,
148
+ now: ariaValueNow ?? accessibilityValue?.now,
149
+ text: ariaValueText ?? accessibilityValue?.text
150
+ };
151
+ }
81
152
  //# 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}\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U,KAAK,CAACE,yBAAyB,KAAK,qBAAqB,EAAE;IACrE,OAAO,IAAI;EACb;;EAEA;EACA,MAAMC,SAAS,GAAGC,uBAAU,CAACC,OAAO,CAACf,OAAO,CAACU,KAAK,CAACM,KAAK,CAAC,IAAI,CAAC,CAAC;EAC/D,IAAIH,SAAS,CAACI,OAAO,KAAK,MAAM,EAAE,OAAO,IAAI;;EAE7C;EACA;EACA,MAAMC,YAAY,GAAG,IAAAC,8BAAe,EAACnB,OAAO,CAAC;EAC7C,IAAIkB,YAAY,CAACE,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACX,KAAK,CAACY,wBAAwB,CAAC,EAAE;IAC1E,OAAO,IAAI;EACb;EAEA,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"],"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"],"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;A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C,YAAY,IAAI,IAAI,IACpBC,YAAY,IAAI,IAAI,IACpBC,YAAY,IAAI,IAAI,IACpBC,aAAa,IAAI,IAAI;EAEvB,IAAI,CAACC,6BAA6B,EAAE;IAClC,OAAOtD,SAAS;EAClB;EAEA,OAAO;IACLuD,GAAG,EAAEL,YAAY,IAAID,kBAAkB,EAAEM,GAAG;IAC5CC,GAAG,EAAEL,YAAY,IAAIF,kBAAkB,EAAEO,GAAG;IAC5CC,GAAG,EAAEL,YAAY,IAAIH,kBAAkB,EAAEQ,GAAG;IAC5ClC,IAAI,EAAE8B,aAAa,IAAIJ,kBAAkB,EAAE1B;EAC7C,CAAC;AACH"}
@@ -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,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"}
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","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,IAAAA,YAAA,GAAAC,OAAA;AAGA,MAAMC,cAAc,GAAG,CACrB,QAAQ,EACR,UAAU,EACV,6BAA6B,EAC7B,0BAA0B,EAC1B,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,OAAO,EACP,cAAc,EACd,OAAO,CACR;;AAED;AACA;AACA;AACO,MAAMC,eAAiC,GAAIC,KAAK,IAAK;EAC1D,MAAMC,MAA+B,GAAG,CAAC,CAAC;EAE1C,MAAMC,MAAM,GAAGC,uBAAU,CAACC,OAAO,CAACJ,KAAK,CAACK,KAAkB,CAAC;EAC3D,IAAIH,MAAM,EAAEI,OAAO,KAAK,MAAM,EAAE;IAC9BL,MAAM,CAACI,KAAK,GAAG;MAAEC,OAAO,EAAE;IAAO,CAAC;EACpC;EAEA,MAAMC,kBAAkB,GAAGC,mBAAmB,CAACR,KAAK,CAACO,kBAAkB,CAAC;EACxE,IAAIA,kBAAkB,KAAKE,SAAS,EAAE;IACpCR,MAAM,CAACM,kBAAkB,GAAGA,kBAAkB;EAChD;EAEA,MAAMG,kBAAkB,GAAGF,mBAAmB,CAACR,KAAK,CAACU,kBAAkB,CAAC;EACxE,IAAIA,kBAAkB,KAAKD,SAAS,EAAE;IACpCR,MAAM,CAACS,kBAAkB,GAAGA,kBAAkB;EAChD;EAEAZ,cAAc,CAACa,OAAO,CAAEC,QAAQ,IAAK;IACnC,IAAIA,QAAQ,IAAIZ,KAAK,EAAE;MACrBC,MAAM,CAACW,QAAQ,CAAC,GAAGZ,KAAK,CAACY,QAAQ,CAAC;IACpC;EACF,CAAC,CAAC;EAEF,OAAOX,MAAM;AACf,CAAC;AAACY,OAAA,CAAAd,eAAA,GAAAA,eAAA;AAEF,SAASe,QAAQA,CAACC,KAAc,EAAoC;EAClE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,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,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C,KAAc,EAAoC;EAClE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC;AAC7E;AAEA,SAASL,mBAAmBA,CAACQ,IAAa,EAAE;EAC1C,IAAI,CAACJ,QAAQ,CAACI,IAAI,CAAC,EAAE;IACnB,OAAOA,IAAI;EACb;EAEA,IAAIC,OAAO,GAAG,KAAK;EACnB,MAAMlB,MAA+B,GAAG,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"}
@@ -9,7 +9,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
9
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; }
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,6 @@ const getCustomPlugin = mapProps => {
27
27
  }
28
28
  };
29
29
  };
30
- function shouldHighlight() {
31
- return process?.env?.COLORS !== 'false';
32
- }
33
30
  var _default = format;
34
31
  exports.default = _default;
35
32
  //# 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,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,C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,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","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","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,IAA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AAK,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,GAEarB,MAAM;AAAAsB,OAAA,CAAArC,OAAA,GAAAoC,QAAA"}
@@ -13,3 +13,8 @@ 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 Modal.
18
+ * @param element The element to check.
19
+ */
20
+ export declare function isHostModal(element?: ReactTestInstance | null): element is HostTestInstance;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.configureHostComponentNamesIfNeeded = configureHostComponentNamesIfNeeded;
7
7
  exports.getHostComponentNames = getHostComponentNames;
8
+ exports.isHostModal = isHostModal;
8
9
  exports.isHostText = isHostText;
9
10
  exports.isHostTextInput = isHostTextInput;
10
11
  var React = _interopRequireWildcard(require("react"));
@@ -43,11 +44,14 @@ function detectHostComponentNames() {
43
44
  testID: "textInput"
44
45
  }), /*#__PURE__*/React.createElement(_reactNative.Switch, {
45
46
  testID: "switch"
47
+ }), /*#__PURE__*/React.createElement(_reactNative.Modal, {
48
+ testID: "modal"
46
49
  })));
47
50
  return {
48
51
  text: getByTestId(renderer.root, 'text').type,
49
52
  textInput: getByTestId(renderer.root, 'textInput').type,
50
- switch: getByTestId(renderer.root, 'switch').type
53
+ switch: getByTestId(renderer.root, 'switch').type,
54
+ modal: getByTestId(renderer.root, 'modal').type
51
55
  };
52
56
  } catch (error) {
53
57
  const errorMessage = error && typeof error === 'object' && 'message' in error ? error.message : null;
@@ -77,4 +81,12 @@ function isHostText(element) {
77
81
  function isHostTextInput(element) {
78
82
  return element?.type === getHostComponentNames().textInput;
79
83
  }
84
+
85
+ /**
86
+ * Checks if the given element is a host Modal.
87
+ * @param element The element to check.
88
+ */
89
+ function isHostModal(element) {
90
+ return element?.type === getHostComponentNames().modal;
91
+ }
80
92
  //# sourceMappingURL=host-component-names.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","Switch","text","getByTestId","root","type","textInput","switch","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length","isHostText","element","isHostTextInput"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Switch, Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\nimport { HostTestInstance } from './component-tree';\n\nconst userConfigErrorMessage = `There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.\nPlease check if you are using compatible versions of React Native and React Native Testing Library.`;\n\nexport function getHostComponentNames(): HostComponentNames {\n let hostComponentNames = getConfig().hostComponentNames;\n if (!hostComponentNames) {\n hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n }\n\n return hostComponentNames;\n}\n\nexport function configureHostComponentNamesIfNeeded() {\n const configHostComponentNames = getConfig().hostComponentNames;\n if (configHostComponentNames) {\n return;\n }\n\n const hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n}\n\nfunction detectHostComponentNames(): HostComponentNames {\n try {\n const renderer = renderWithAct(\n <View>\n <Text testID=\"text\">Hello</Text>\n <TextInput testID=\"textInput\" />\n <Switch testID=\"switch\" />\n </View>\n );\n\n return {\n text: getByTestId(renderer.root, 'text').type as string,\n textInput: getByTestId(renderer.root, 'textInput').type as string,\n switch: getByTestId(renderer.root, 'switch').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error\n ? error.message\n : null;\n\n throw new Error(\n `Trying to detect host component names triggered the following error:\\n\\n${errorMessage}\\n\\n${userConfigErrorMessage}`\n );\n }\n}\n\nfunction getByTestId(instance: ReactTestInstance, testID: string) {\n const nodes = instance.findAll(\n (node) => typeof node.type === 'string' && node.props.testID === testID\n );\n\n if (nodes.length === 0) {\n throw new Error(`Unable to find an element with testID: ${testID}`);\n }\n\n return nodes[0];\n}\n\n/**\n * Checks if the given element is a host Text.\n * @param element The element to check.\n */\nexport function isHostText(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return element?.type === getHostComponentNames().text;\n}\n\n/**\n * Checks if the given element is a host TextInput.\n * @param element The element to check.\n */\nexport function isHostT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,CAACU,IAAI,EAAE,WAAW,CAAC,CAACC,IAAc;MACjEE,MAAM,EAAEJ,WAAW,CAACT,QAAQ,CAACU,IAAI,EAAE,QAAQ,CAAC,CAACC;IAC/C,CAAC;EACH,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAMC,YAAY,GAChBD,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAIA,KAAK,GACpDA,KAAK,CAACE,OAAO,GACb,IAAI;IAEV,MAAM,IAAIC,KAAK,CACZ,2EAA0EF,YAAa,OAAMvB,sBAAuB,EACvH,CAAC;EACH;AACF;AAEA,SAASiB,WAAWA,CAACS,QAA2B,EAAEb,MAAc,EAAE;EAChE,MAAMc,KAAK,GAAGD,QAAQ,CAACE,OAAO,CAC3BC,IAAI,IAAK,OAAOA,IAAI,CAACV,IAAI,KAAK,QAAQ,IAAIU,IAAI,CAACC,KAAK,CAACjB,MAAM,KAAKA,MACnE,CAAC;EAED,IAAIc,KAAK,CAACI,MAAM,KAAK,CAAC,EAAE;IACtB,MAAM,IAAIN,KAAK,CAAE,0CAAyCZ,MAAO,EAAC,CAAC;EACrE;EAEA,OAAOc,KAAK,CAAC,CAAC,CAAC;AACjB;;AAEA;AACA;AACA;AACA;AACO,SAASK,UAAUA,CACxBC,OAAkC,EACL;EAC7B,OAAOA,OAAO,EAAEd,IAAI,KAAKlB,qBAAqB,CAAC,CAAC,CAACe,IAAI;AACvD;;AAEA;AACA;AACA;AACA;AACO,SAASkB,eAAeA,CAC7BD,OAAkC,EACL;EAC7B,OAAOA,OAAO,EAAEd,IAAI,KAAKlB,qBAAqB,CAAC,CAAC,CAACmB,SAAS;AAC5D"}
1
+ {"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","Switch","Modal","text","getByTestId","root","type","textInput","switch","modal","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length","isHostText","element","isHostTextInput","isHostModal"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Modal, Switch, Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\nimport { HostTestInstance } from './component-tree';\n\nconst userConfigErrorMessage = `There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.\nPlease check if you are using compatible versions of React Native and React Native Testing Library.`;\n\nexport function getHostComponentNames(): HostComponentNames {\n let hostComponentNames = getConfig().hostComponentNames;\n if (!hostComponentNames) {\n hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n }\n\n return hostComponentNames;\n}\n\nexport function configureHostComponentNamesIfNeeded() {\n const configHostComponentNames = getConfig().hostComponentNames;\n if (configHostComponentNames) {\n return;\n }\n\n const hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n}\n\nfunction detectHostComponentNames(): HostComponentNames {\n try {\n const renderer = renderWithAct(\n <View>\n <Text testID=\"text\">Hello</Text>\n <TextInput testID=\"textInput\" />\n <Switch testID=\"switch\" />\n <Modal testID=\"modal\" />\n </View>\n );\n\n return {\n text: getByTestId(renderer.root, 'text').type as string,\n textInput: getByTestId(renderer.root, 'textInput').type as string,\n switch: getByTestId(renderer.root, 'switch').type as string,\n modal: getByTestId(renderer.root, 'modal').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error\n ? error.message\n : null;\n\n throw new Error(\n `Trying to detect host component names triggered the following error:\\n\\n${errorMessage}\\n\\n${userConfigErrorMessage}`\n );\n }\n}\n\nfunction getByTestId(instance: ReactTestInstance, testID: string) {\n const nodes = instance.findAll(\n (node) => typeof node.type === 'string' && node.props.testID === testID\n );\n\n if (nodes.length === 0) {\n throw new Error(`Unable to find an element with testID: ${testID}`);\n }\n\n return nodes[0];\n}\n\n/**\n * Checks if the given element is a host Text.\n * @param element The element to check.\n */\nexport function isHostText(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return element?.type === getHostComponentNames().text;\n}\n\n/**\n * Checks if the given element is a host TextInput.\n * @param element The element to check.\n */\nexport function isHostTextInput(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return element?.type === getHostComponentNames().textInput;\n}\n\n/**\n * Checks if the given element is a host Modal.\n * @param element The element to check.\n */\nexport function isHostModal(\n element?: ReactTestInstance | null\n): element is HostTestInstance {\n return element?.type === getHostComponentNames().modal;\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAA8C,SAAAI,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,SAAAN,wBAAAU,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,q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M,KAAKA,MACnE,CAAC;EAED,IAAIgB,KAAK,CAACI,MAAM,KAAK,CAAC,EAAE;IACtB,MAAM,IAAIN,KAAK,CAAE,0CAAyCd,MAAO,EAAC,CAAC;EACrE;EAEA,OAAOgB,KAAK,CAAC,CAAC,CAAC;AACjB;;AAEA;AACA;AACA;AACA;AACO,SAASK,UAAUA,CACxBC,OAAkC,EACL;EAC7B,OAAOA,OAAO,EAAEf,IAAI,KAAKnB,qBAAqB,CAAC,CAAC,CAACgB,IAAI;AACvD;;AAEA;AACA;AACA;AACA;AACO,SAASmB,eAAeA,CAC7BD,OAAkC,EACL;EAC7B,OAAOA,OAAO,EAAEf,IAAI,KAAKnB,qBAAqB,CAAC,CAAC,CAACoB,SAAS;AAC5D;;AAEA;AACA;AACA;AACA;AACO,SAASgB,WAAWA,CACzBF,OAAkC,EACL;EAC7B,OAAOA,OAAO,EAAEf,IAAI,KAAKnB,qBAAqB,CAAC,CAAC,CAACsB,KAAK;AACxD"}
@@ -23,10 +23,10 @@ const defaultState = {
23
23
  expanded: undefined
24
24
  };
25
25
  function matchAccessibilityState(node, matcher) {
26
- const state = node.props.accessibilityState;
27
- return _accessiblity.accessibilityStateKeys.every(key => matchState(state, matcher, key));
26
+ const state = (0, _accessiblity.getAccessibilityState)(node);
27
+ return _accessiblity.accessibilityStateKeys.every(key => matchState(matcher, state, key));
28
28
  }
29
- function matchState(state, matcher, key) {
29
+ function matchState(matcher, state, key) {
30
30
  return matcher[key] === undefined || matcher[key] === (state?.[key] ?? defaultState[key]);
31
31
  }
32
32
  //# sourceMappingURL=accessibilityState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessibilityState.js","names":["_accessiblity","require","defaultState","disabled","selected","checked","undefined","busy","expanded","matchAccessibilityState","node","matcher","state","props","accessibilityState","accessibilityStateKeys","every","key","matchState"],"sources":["../../../src/helpers/matchers/accessibilityState.ts"],"sourcesContent":["import { AccessibilityState } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { accessibilityStateKeys } from '../accessiblity';\n\n// This type is the same as AccessibilityState from `react-native` package\n// It is re-declared here due to issues with migration from `@types/react-native` to\n// built in `react-native` types.\n// See: https://github.com/callstack/react-native-testing-library/issues/1351\nexport interface AccessibilityStateMatcher {\n disabled?: boolean;\n selected?: boolean;\n checked?: boolean | 'mixed';\n busy?: boolean;\n expanded?: boolean;\n}\n\n/**\n * Default accessibility state values based on experiments using accessibility\n * inspector/screen reader on iOS and Android.\n *\n * @see https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State\n */\nconst defaultState: AccessibilityState = {\n disabled: false,\n selected: false,\n checked: undefined,\n busy: false,\n expanded: undefined,\n};\n\nexport function matchAccessibilityState(\n node: ReactTestInstance,\n matcher: AccessibilityStateMatcher\n) {\n const state = node.props.accessibilityState;\n return accessibilityStateKeys.every((key) => matchState(state, matcher, key));\n}\n\nfunction matchState(\n state: AccessibilityState,\n matcher: AccessibilityStateMatcher,\n key: keyof AccessibilityState\n) {\n return (\n matcher[key] === undefined ||\n matcher[key] === (state?.[key] ?? defaultState[key])\n );\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAgC,GAAG;EACvCC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,KAAK;EACfC,OAAO,EAAEC,SAAS;EAClBC,IAAI,EAAE,KAAK;EACXC,QAAQ,EAAEF;AACZ,CAAC;AAEM,SAASG,uBAAuBA,CACrCC,IAAuB,EACvBC,OAAkC,EAClC;EACA,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAACC,kBAAkB;EAC3C,OAAOC,oCAAsB,CAACC,KAAK,CAAEC,GAAG,IAAKC,UAAU,CAACN,KAAK,EAAED,OAAO,EAAEM,GAAG,CAAC,CAAC;AAC/E;AAEA,SAASC,UAAUA,CACjBN,KAAyB,EACzBD,OAAkC,EAClCM,GAA6B,EAC7B;EACA,OACEN,OAAO,CAACM,GAAG,CAAC,KAAKX,SAAS,IAC1BK,OAAO,CAACM,GAAG,CAAC,MAAML,KAAK,GAAGK,GAAG,CAAC,IAAIf,YAAY,CAACe,GAAG,CAAC,CAAC;AAExD"}
1
+ {"version":3,"file":"accessibilityState.js","names":["_accessiblity","require","defaultState","disabled","selected","checked","undefined","busy","expanded","matchAccessibilityState","node","matcher","state","getAccessibilityState","accessibilityStateKeys","every","key","matchState"],"sources":["../../../src/helpers/matchers/accessibilityState.ts"],"sourcesContent":["import { AccessibilityState } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { accessibilityStateKeys, getAccessibilityState } from '../accessiblity';\n\n// This type is the same as AccessibilityState from `react-native` package\n// It is re-declared here due to issues with migration from `@types/react-native` to\n// built in `react-native` types.\n// See: https://github.com/callstack/react-native-testing-library/issues/1351\nexport interface AccessibilityStateMatcher {\n disabled?: boolean;\n selected?: boolean;\n checked?: boolean | 'mixed';\n busy?: boolean;\n expanded?: boolean;\n}\n\n/**\n * Default accessibility state values based on experiments using accessibility\n * inspector/screen reader on iOS and Android.\n *\n * @see https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State\n */\nconst defaultState: AccessibilityState = {\n disabled: false,\n selected: false,\n checked: undefined,\n busy: false,\n expanded: undefined,\n};\n\nexport function matchAccessibilityState(\n node: ReactTestInstance,\n matcher: AccessibilityStateMatcher\n) {\n const state = getAccessibilityState(node);\n return accessibilityStateKeys.every((key) => matchState(matcher, state, key));\n}\n\nfunction matchState(\n matcher: AccessibilityStateMatcher,\n state: AccessibilityState | undefined,\n key: keyof AccessibilityState\n) {\n return (\n matcher[key] === undefined ||\n matcher[key] === (state?.[key] ?? defaultState[key])\n );\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAgC,GAAG;EACvCC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,KAAK;EACfC,OAAO,EAAEC,SAAS;EAClBC,IAAI,EAAE,KAAK;EACXC,QAAQ,EAAEF;AACZ,CAAC;AAEM,SAASG,uBAAuBA,CACrCC,IAAuB,EACvBC,OAAkC,EAClC;EACA,MAAMC,KAAK,GAAG,IAAAC,mCAAqB,EAACH,IAAI,CAAC;EACzC,OAAOI,oCAAsB,CAACC,KAAK,CAAEC,GAAG,IAAKC,UAAU,CAACN,OAAO,EAAEC,KAAK,EAAEI,GAAG,CAAC,CAAC;AAC/E;AAEA,SAASC,UAAUA,CACjBN,OAAkC,EAClCC,KAAqC,EACrCI,GAA6B,EAC7B;EACA,OACEL,OAAO,CAACK,GAAG,CAAC,KAAKV,SAAS,IAC1BK,OAAO,CAACK,GAAG,CAAC,MAAMJ,KAAK,GAAGI,GAAG,CAAC,IAAId,YAAY,CAACc,GAAG,CAAC,CAAC;AAExD"}
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.matchAccessibilityValue = matchAccessibilityValue;
7
+ var _accessiblity = require("../accessiblity");
7
8
  var _matchStringProp = require("./matchStringProp");
8
9
  function matchAccessibilityValue(node, matcher) {
9
- const value = node.props.accessibilityValue ?? {};
10
- return (matcher.min === undefined || matcher.min === value.min) && (matcher.max === undefined || matcher.max === value.max) && (matcher.now === undefined || matcher.now === value.now) && (matcher.text === undefined || (0, _matchStringProp.matchStringProp)(value.text, matcher.text));
10
+ const value = (0, _accessiblity.getAccessibilityValue)(node);
11
+ return (matcher.min === undefined || matcher.min === value?.min) && (matcher.max === undefined || matcher.max === value?.max) && (matcher.now === undefined || matcher.now === value?.now) && (matcher.text === undefined || (0, _matchStringProp.matchStringProp)(value?.text, matcher.text));
11
12
  }
12
13
  //# sourceMappingURL=accessibilityValue.js.map