@testing-library/react-native 11.3.0 → 11.4.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 (97) hide show
  1. package/README.md +3 -0
  2. package/build/act.js +9 -15
  3. package/build/act.js.map +1 -1
  4. package/build/cleanup.js +0 -4
  5. package/build/cleanup.js.map +1 -1
  6. package/build/config.d.ts +5 -0
  7. package/build/config.js +4 -5
  8. package/build/config.js.map +1 -1
  9. package/build/fireEvent.js +3 -31
  10. package/build/fireEvent.js.map +1 -1
  11. package/build/flushMicroTasks.js +0 -3
  12. package/build/flushMicroTasks.js.map +1 -1
  13. package/build/helpers/accessiblity.d.ts +3 -0
  14. package/build/helpers/accessiblity.js +14 -20
  15. package/build/helpers/accessiblity.js.map +1 -1
  16. package/build/helpers/component-tree.js +6 -27
  17. package/build/helpers/component-tree.js.map +1 -1
  18. package/build/helpers/debugDeep.d.ts +5 -1
  19. package/build/helpers/debugDeep.js +7 -6
  20. package/build/helpers/debugDeep.js.map +1 -1
  21. package/build/helpers/debugShallow.js +0 -5
  22. package/build/helpers/debugShallow.js.map +1 -1
  23. package/build/helpers/errors.js +4 -25
  24. package/build/helpers/errors.js.map +1 -1
  25. package/build/helpers/filterNodeByType.js +0 -2
  26. package/build/helpers/filterNodeByType.js.map +1 -1
  27. package/build/helpers/format.d.ts +5 -1
  28. package/build/helpers/format.js +17 -7
  29. package/build/helpers/format.js.map +1 -1
  30. package/build/helpers/matchers/accessibilityState.d.ts +3 -0
  31. package/build/helpers/matchers/accessibilityState.js +28 -0
  32. package/build/helpers/matchers/accessibilityState.js.map +1 -0
  33. package/build/helpers/matchers/matchArrayProp.js +0 -3
  34. package/build/helpers/matchers/matchArrayProp.js.map +1 -1
  35. package/build/helpers/matchers/matchObjectProp.js +0 -2
  36. package/build/helpers/matchers/matchObjectProp.js.map +1 -1
  37. package/build/helpers/matchers/matchStringProp.js +0 -3
  38. package/build/helpers/matchers/matchStringProp.js.map +1 -1
  39. package/build/helpers/stringValidation.js +0 -7
  40. package/build/helpers/stringValidation.js.map +1 -1
  41. package/build/helpers/timers.js +10 -21
  42. package/build/helpers/timers.js.map +1 -1
  43. package/build/index.flow.js +66 -21
  44. package/build/index.js +0 -6
  45. package/build/index.js.map +1 -1
  46. package/build/matches.js +2 -4
  47. package/build/matches.js.map +1 -1
  48. package/build/pure.js +0 -13
  49. package/build/pure.js.map +1 -1
  50. package/build/queries/a11yState.js +15 -13
  51. package/build/queries/a11yState.js.map +1 -1
  52. package/build/queries/a11yValue.js +0 -8
  53. package/build/queries/a11yValue.js.map +1 -1
  54. package/build/queries/displayValue.js +0 -11
  55. package/build/queries/displayValue.js.map +1 -1
  56. package/build/queries/hintText.d.ts +19 -18
  57. package/build/queries/hintText.js +10 -11
  58. package/build/queries/hintText.js.map +1 -1
  59. package/build/queries/labelText.d.ts +7 -6
  60. package/build/queries/labelText.js +10 -11
  61. package/build/queries/labelText.js.map +1 -1
  62. package/build/queries/makeQueries.d.ts +3 -3
  63. package/build/queries/makeQueries.js +40 -24
  64. package/build/queries/makeQueries.js.map +1 -1
  65. package/build/queries/placeholderText.js +0 -11
  66. package/build/queries/placeholderText.js.map +1 -1
  67. package/build/queries/role.d.ts +3 -2
  68. package/build/queries/role.js +23 -13
  69. package/build/queries/role.js.map +1 -1
  70. package/build/queries/testId.js +0 -9
  71. package/build/queries/testId.js.map +1 -1
  72. package/build/queries/text.js +0 -24
  73. package/build/queries/text.js.map +1 -1
  74. package/build/queries/unsafeProps.js +2 -11
  75. package/build/queries/unsafeProps.js.map +1 -1
  76. package/build/queries/unsafeType.js +2 -9
  77. package/build/queries/unsafeType.js.map +1 -1
  78. package/build/react-versions.js +0 -4
  79. package/build/react-versions.js.map +1 -1
  80. package/build/render.d.ts +32 -31
  81. package/build/render.js +21 -31
  82. package/build/render.js.map +1 -1
  83. package/build/renderHook.js +2 -12
  84. package/build/renderHook.js.map +1 -1
  85. package/build/screen.js +0 -6
  86. package/build/screen.js.map +1 -1
  87. package/build/shallow.js +0 -6
  88. package/build/shallow.js.map +1 -1
  89. package/build/waitFor.js +29 -52
  90. package/build/waitFor.js.map +1 -1
  91. package/build/waitForElementToBeRemoved.js +2 -11
  92. package/build/waitForElementToBeRemoved.js.map +1 -1
  93. package/build/within.d.ts +30 -30
  94. package/build/within.js +2 -14
  95. package/build/within.js.map +1 -1
  96. package/package.json +9 -8
  97. package/typings/index.flow.js +66 -21
package/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  [![Version][version-badge]][package]
13
13
  [![PRs Welcome][prs-welcome-badge]][prs-welcome]
14
14
  [![Chat][chat-badge]][chat]
15
+ [![codecov][codecov-badge]][codecov]
15
16
  [![Sponsored by Callstack][callstack-badge]][callstack]
16
17
 
17
18
  ## The problem
@@ -171,3 +172,5 @@ Supported and used by [Rally Health](https://www.rallyhealth.com/careers-home).
171
172
  [chat]: https://discord.gg/QbGezWe
172
173
  [callstack-badge]: https://callstack.com/images/callstack-badge.svg
173
174
  [callstack]: https://callstack.com/open-source/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-testing-library&utm_term=readme
175
+ [codecov-badge]: https://codecov.io/gh/callstack/react-native-testing-library/branch/main/graph/badge.svg?token=tYVSWro1IP
176
+ [codecov]: https://codecov.io/gh/callstack/react-native-testing-library
package/build/act.js CHANGED
@@ -6,52 +6,49 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  exports.getIsReactActEnvironment = getIsReactActEnvironment;
8
8
  exports.setReactActEnvironment = setIsReactActEnvironment;
9
-
10
9
  var _reactTestRenderer = require("react-test-renderer");
11
-
12
10
  var _reactVersions = require("./react-versions");
13
-
14
11
  // This file and the act() implementation is sourced from react-testing-library
15
12
  // https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js
13
+
16
14
  const actMock = callback => {
17
15
  callback();
18
- }; // See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT
16
+ };
19
17
 
18
+ // See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT
20
19
 
21
20
  function setIsReactActEnvironment(isReactActEnvironment) {
22
21
  globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
23
22
  }
24
-
25
23
  function getIsReactActEnvironment() {
26
24
  return globalThis.IS_REACT_ACT_ENVIRONMENT;
27
25
  }
28
-
29
26
  function withGlobalActEnvironment(actImplementation) {
30
27
  return callback => {
31
28
  const previousActEnvironment = getIsReactActEnvironment();
32
- setIsReactActEnvironment(true); // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do
29
+ setIsReactActEnvironment(true);
33
30
 
31
+ // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do
34
32
  try {
35
33
  // The return value of `act` is always a thenable.
36
34
  let callbackNeedsToBeAwaited = false;
37
35
  const actResult = actImplementation(() => {
38
36
  const result = callback();
39
-
40
- if (result !== null && typeof result === 'object' && // @ts-expect-error this should be a promise or thenable
37
+ if (result !== null && typeof result === 'object' &&
38
+ // @ts-expect-error this should be a promise or thenable
41
39
  // eslint-disable-next-line promise/prefer-await-to-then
42
40
  typeof result.then === 'function') {
43
41
  callbackNeedsToBeAwaited = true;
44
42
  }
45
-
46
43
  return result;
47
44
  });
48
-
49
45
  if (callbackNeedsToBeAwaited) {
50
46
  const thenable = actResult;
51
47
  return {
52
48
  then: (resolve, reject) => {
53
49
  // eslint-disable-next-line
54
- thenable.then( // eslint-disable-next-line promise/always-return
50
+ thenable.then(
51
+ // eslint-disable-next-line promise/always-return
55
52
  returnValue => {
56
53
  setIsReactActEnvironment(previousActEnvironment);
57
54
  resolve(returnValue);
@@ -73,15 +70,12 @@ function withGlobalActEnvironment(actImplementation) {
73
70
  }
74
71
  };
75
72
  }
76
-
77
73
  const getAct = () => {
78
74
  if (!_reactTestRenderer.act) {
79
75
  return actMock;
80
76
  }
81
-
82
77
  return (0, _reactVersions.checkReactVersionAtLeast)(18, 0) ? withGlobalActEnvironment(_reactTestRenderer.act) : _reactTestRenderer.act;
83
78
  };
84
-
85
79
  const act = getAct();
86
80
  var _default = act;
87
81
  exports.default = _default;
package/build/act.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"act.js","names":["actMock","callback","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","getAct","reactTestRendererAct","checkReactVersionAtLeast","act"],"sources":["../src/act.ts"],"sourcesContent":["// This file and the act() implementation is sourced from react-testing-library\n// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js\nimport { act as reactTestRendererAct } from 'react-test-renderer';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst actMock = (callback: () => void) => {\n callback();\n};\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\ntype Act = typeof reactTestRendererAct;\n\nfunction withGlobalActEnvironment(actImplementation: Act) {\n return (callback: Parameters<Act>[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 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}\nconst getAct = () => {\n if (!reactTestRendererAct) {\n return actMock;\n }\n\n return checkReactVersionAtLeast(18, 0)\n ? withGlobalActEnvironment(reactTestRendererAct)\n : reactTestRendererAct;\n};\nconst act = getAct();\n\nexport default act;\nexport {\n setIsReactActEnvironment as setReactActEnvironment,\n getIsReactActEnvironment,\n};\n"],"mappings":";;;;;;;;;AAEA;;AACA;;AAHA;AACA;AAIA,MAAMA,OAAO,GAAIC,QAAD,IAA0B;EACxCA,QAAQ;AACT,CAFD,C,CAIA;;;AAKA,SAASC,wBAAT,CAAkCC,qBAAlC,EAA8E;EAC5EC,UAAU,CAACC,wBAAX,GAAsCF,qBAAtC;AACD;;AAED,SAASG,wBAAT,GAAoC;EAClC,OAAOF,UAAU,CAACC,wBAAlB;AACD;;AAID,SAASE,wBAAT,CAAkCC,iBAAlC,EAA0D;EACxD,OAAQP,QAAD,IAAkC;IACvC,MAAMQ,sBAAsB,GAAGH,wBAAwB,EAAvD;IACAJ,wBAAwB,CAAC,IAAD,CAAxB,CAFuC,CAIvC;;IACA,IAAI;MACF;MACA,IAAIQ,wBAAwB,GAAG,KAA/B;MACA,MAAMC,SAAS,GAAGH,iBAAiB,CAAC,MAAM;QACxC,MAAMI,MAAM,GAAGX,QAAQ,EAAvB;;QACA,IACEW,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEA;QACA;QACA,OAAOA,MAAM,CAACC,IAAd,KAAuB,UALzB,EAME;UACAH,wBAAwB,GAAG,IAA3B;QACD;;QACD,OAAOE,MAAP;MACD,CAZkC,CAAnC;;MAaA,IAAIF,wBAAJ,EAA8B;QAC5B,MAAMI,QAAQ,GAAGH,SAAjB;QACA,OAAO;UACLE,IAAI,EAAE,CACJE,OADI,EAEJC,MAFI,KAGD;YACH;YACAF,QAAQ,CAACD,IAAT,EACE;YACCI,WAAD,IAAiB;cACff,wBAAwB,CAACO,sBAAD,CAAxB;cACAM,OAAO,CAACE,WAAD,CAAP;YACD,CALH,EAMGC,KAAD,IAAW;cACThB,wBAAwB,CAACO,sBAAD,CAAxB;cACAO,MAAM,CAACE,KAAD,CAAN;YACD,CATH;UAWD;QAjBI,CAAP;MAmBD,CArBD,MAqBO;QACLhB,wBAAwB,CAACO,sBAAD,CAAxB;QACA,OAAOE,SAAP;MACD;IACF,CAzCD,CAyCE,OAAOO,KAAP,EAAc;MACd;MACA;MACAhB,wBAAwB,CAACO,sBAAD,CAAxB;MACA,MAAMS,KAAN;IACD;EACF,CApDD;AAqDD;;AACD,MAAMC,MAAM,GAAG,MAAM;EACnB,IAAI,CAACC,sBAAL,EAA2B;IACzB,OAAOpB,OAAP;EACD;;EAED,OAAO,IAAAqB,uCAAA,EAAyB,EAAzB,EAA6B,CAA7B,IACHd,wBAAwB,CAACa,sBAAD,CADrB,GAEHA,sBAFJ;AAGD,CARD;;AASA,MAAME,GAAG,GAAGH,MAAM,EAAlB;eAEeG,G"}
1
+ {"version":3,"file":"act.js","names":["actMock","callback","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","getAct","reactTestRendererAct","checkReactVersionAtLeast","act"],"sources":["../src/act.ts"],"sourcesContent":["// This file and the act() implementation is sourced from react-testing-library\n// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js\nimport { act as reactTestRendererAct } from 'react-test-renderer';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst actMock = (callback: () => void) => {\n callback();\n};\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\ntype Act = typeof reactTestRendererAct;\n\nfunction withGlobalActEnvironment(actImplementation: Act) {\n return (callback: Parameters<Act>[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 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}\nconst getAct = () => {\n if (!reactTestRendererAct) {\n return actMock;\n }\n\n return checkReactVersionAtLeast(18, 0)\n ? withGlobalActEnvironment(reactTestRendererAct)\n : reactTestRendererAct;\n};\nconst act = getAct();\n\nexport default act;\nexport {\n setIsReactActEnvironment as setReactActEnvironment,\n getIsReactActEnvironment,\n};\n"],"mappings":";;;;;;;;AAEA;AACA;AAHA;AACA;;AAIA,MAAMA,OAAO,GAAIC,QAAoB,IAAK;EACxCA,QAAQ,EAAE;AACZ,CAAC;;AAED;;AAKA,SAASC,wBAAwB,CAACC,qBAA0C,EAAE;EAC5EC,UAAU,CAACC,wBAAwB,GAAGF,qBAAqB;AAC7D;AAEA,SAASG,wBAAwB,GAAG;EAClC,OAAOF,UAAU,CAACC,wBAAwB;AAC5C;AAIA,SAASE,wBAAwB,CAACC,iBAAsB,EAAE;EACxD,OAAQP,QAA4B,IAAK;IACvC,MAAMQ,sBAAsB,GAAGH,wBAAwB,EAAE;IACzDJ,wBAAwB,CAAC,IAAI,CAAC;;IAE9B;IACA,IAAI;MACF;MACA,IAAIQ,wBAAwB,GAAG,KAAK;MACpC,MAAMC,SAAS,GAAGH,iBAAiB,CAAC,MAAM;QACxC,MAAMI,MAAM,GAAGX,QAAQ,EAAE;QACzB,IACEW,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;MACF,IAAIF,wBAAwB,EAAE;QAC5B,MAAMI,QAAQ,GAAGH,SAAS;QAC1B,OAAO;UACLE,IAAI,EAAE,CACJE,OAAgC,EAChCC,MAA+B,KAC5B;YACH;YACAF,QAAQ,CAACD,IAAI;YACX;YACCI,WAAW,IAAK;cACff,wBAAwB,CAACO,sBAAsB,CAAC;cAChDM,OAAO,CAACE,WAAW,CAAC;YACtB,CAAC,EACAC,KAAK,IAAK;cACThB,wBAAwB,CAACO,sBAAsB,CAAC;cAChDO,MAAM,CAACE,KAAK,CAAC;YACf,CAAC,CACF;UACH;QACF,CAAC;MACH,CAAC,MAAM;QACLhB,wBAAwB,CAACO,sBAAsB,CAAC;QAChD,OAAOE,SAAS;MAClB;IACF,CAAC,CAAC,OAAOO,KAAK,EAAE;MACd;MACA;MACAhB,wBAAwB,CAACO,sBAAsB,CAAC;MAChD,MAAMS,KAAK;IACb;EACF,CAAC;AACH;AACA,MAAMC,MAAM,GAAG,MAAM;EACnB,IAAI,CAACC,sBAAoB,EAAE;IACzB,OAAOpB,OAAO;EAChB;EAEA,OAAO,IAAAqB,uCAAwB,EAAC,EAAE,EAAE,CAAC,CAAC,GAClCd,wBAAwB,CAACa,sBAAoB,CAAC,GAC9CA,sBAAoB;AAC1B,CAAC;AACD,MAAME,GAAG,GAAGH,MAAM,EAAE;AAAC,eAENG,GAAG;AAAA"}
package/build/cleanup.js CHANGED
@@ -5,17 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.addToCleanupQueue = addToCleanupQueue;
7
7
  exports.default = cleanup;
8
-
9
8
  var _screen = require("./screen");
10
-
11
9
  let cleanupQueue = new Set();
12
-
13
10
  function cleanup() {
14
11
  (0, _screen.clearRenderResult)();
15
12
  cleanupQueue.forEach(fn => fn());
16
13
  cleanupQueue.clear();
17
14
  }
18
-
19
15
  function addToCleanupQueue(fn) {
20
16
  cleanupQueue.add(fn);
21
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup.js","names":["cleanupQueue","Set","cleanup","clearRenderResult","forEach","fn","clear","addToCleanupQueue","add"],"sources":["../src/cleanup.ts"],"sourcesContent":["import * as React from 'react';\nimport { clearRenderResult } from './screen';\n\ntype CleanUpFunction = (nextElement?: React.ReactElement<any>) => void;\nlet cleanupQueue = new Set<CleanUpFunction>();\n\nexport default function cleanup() {\n clearRenderResult();\n cleanupQueue.forEach((fn) => fn());\n cleanupQueue.clear();\n}\n\nexport function addToCleanupQueue(fn: CleanUpFunction) {\n cleanupQueue.add(fn);\n}\n"],"mappings":";;;;;;;;AACA;;AAGA,IAAIA,YAAY,GAAG,IAAIC,GAAJ,EAAnB;;AAEe,SAASC,OAAT,GAAmB;EAChC,IAAAC,yBAAA;EACAH,YAAY,CAACI,OAAb,CAAsBC,EAAD,IAAQA,EAAE,EAA/B;EACAL,YAAY,CAACM,KAAb;AACD;;AAEM,SAASC,iBAAT,CAA2BF,EAA3B,EAAgD;EACrDL,YAAY,CAACQ,GAAb,CAAiBH,EAAjB;AACD"}
1
+ {"version":3,"file":"cleanup.js","names":["cleanupQueue","Set","cleanup","clearRenderResult","forEach","fn","clear","addToCleanupQueue","add"],"sources":["../src/cleanup.ts"],"sourcesContent":["import * as React from 'react';\nimport { clearRenderResult } from './screen';\n\ntype CleanUpFunction = (nextElement?: React.ReactElement<any>) => void;\nlet cleanupQueue = new Set<CleanUpFunction>();\n\nexport default function cleanup() {\n clearRenderResult();\n cleanupQueue.forEach((fn) => fn());\n cleanupQueue.clear();\n}\n\nexport function addToCleanupQueue(fn: CleanUpFunction) {\n cleanupQueue.add(fn);\n}\n"],"mappings":";;;;;;;AACA;AAGA,IAAIA,YAAY,GAAG,IAAIC,GAAG,EAAmB;AAE9B,SAASC,OAAO,GAAG;EAChC,IAAAC,yBAAiB,GAAE;EACnBH,YAAY,CAACI,OAAO,CAAEC,EAAE,IAAKA,EAAE,EAAE,CAAC;EAClCL,YAAY,CAACM,KAAK,EAAE;AACtB;AAEO,SAASC,iBAAiB,CAACF,EAAmB,EAAE;EACrDL,YAAY,CAACQ,GAAG,CAACH,EAAE,CAAC;AACtB"}
package/build/config.d.ts CHANGED
@@ -1,10 +1,15 @@
1
+ import { DebugOptions } from './helpers/debugDeep';
1
2
  export declare type Config = {
2
3
  /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
3
4
  asyncUtilTimeout: number;
5
+ /** Default options for `debug` helper. */
6
+ defaultDebugOptions?: Partial<DebugOptions>;
4
7
  };
5
8
  export declare function configure(options: Partial<Config>): void;
6
9
  export declare function resetToDefaults(): void;
7
10
  export declare function getConfig(): {
8
11
  /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
9
12
  asyncUtilTimeout: number;
13
+ /** Default options for `debug` helper. */
14
+ defaultDebugOptions?: Partial<DebugOptions> | undefined;
10
15
  };
package/build/config.js CHANGED
@@ -9,19 +9,18 @@ exports.resetToDefaults = resetToDefaults;
9
9
  const defaultConfig = {
10
10
  asyncUtilTimeout: 1000
11
11
  };
12
- let config = { ...defaultConfig
12
+ let config = {
13
+ ...defaultConfig
13
14
  };
14
-
15
15
  function configure(options) {
16
- config = { ...config,
16
+ config = {
17
+ ...config,
17
18
  ...options
18
19
  };
19
20
  }
20
-
21
21
  function resetToDefaults() {
22
22
  config = defaultConfig;
23
23
  }
24
-
25
24
  function getConfig() {
26
25
  return config;
27
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","config","configure","options","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["export type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n};\n\nconst defaultConfig: Config = {\n asyncUtilTimeout: 1000,\n};\n\nlet config = {\n ...defaultConfig,\n};\n\nexport function configure(options: Partial<Config>) {\n config = {\n ...config,\n ...options,\n };\n}\n\nexport function resetToDefaults() {\n config = defaultConfig;\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AAKA,MAAMA,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE;AADU,CAA9B;AAIA,IAAIC,MAAM,GAAG,EACX,GAAGF;AADQ,CAAb;;AAIO,SAASG,SAAT,CAAmBC,OAAnB,EAA6C;EAClDF,MAAM,GAAG,EACP,GAAGA,MADI;IAEP,GAAGE;EAFI,CAAT;AAID;;AAEM,SAASC,eAAT,GAA2B;EAChCH,MAAM,GAAGF,aAAT;AACD;;AAEM,SAASM,SAAT,GAAqB;EAC1B,OAAOJ,MAAP;AACD"}
1
+ {"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","config","configure","options","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debugDeep';\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nconst defaultConfig: Config = {\n asyncUtilTimeout: 1000,\n};\n\nlet config = {\n ...defaultConfig,\n};\n\nexport function configure(options: Partial<Config>) {\n config = {\n ...config,\n ...options,\n };\n}\n\nexport function resetToDefaults() {\n config = defaultConfig;\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AAUA,MAAMA,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE;AACpB,CAAC;AAED,IAAIC,MAAM,GAAG;EACX,GAAGF;AACL,CAAC;AAEM,SAASG,SAAS,CAACC,OAAwB,EAAE;EAClDF,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGE;EACL,CAAC;AACH;AAEO,SAASC,eAAe,GAAG;EAChCH,MAAM,GAAGF,aAAa;AACxB;AAEO,SAASM,SAAS,GAAG;EAC1B,OAAOJ,MAAM;AACf"}
@@ -4,51 +4,39 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _reactNative = require("react-native");
9
-
10
8
  var _act = _interopRequireDefault(require("./act"));
11
-
12
9
  var _componentTree = require("./helpers/component-tree");
13
-
14
10
  var _filterNodeByType = require("./helpers/filterNodeByType");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  const isTextInput = element => {
19
13
  if (!element) {
20
14
  return false;
21
- } // We have to test if the element type is either the TextInput component
15
+ }
16
+
17
+ // We have to test if the element type is either the TextInput component
22
18
  // (which would if it is a composite component) or the string
23
19
  // TextInput (which would be true if it is a host component)
24
20
  // All queries but the one by testID return composite component and event
25
21
  // if all queries returned host components, since fireEvent bubbles up
26
22
  // it would trigger the parent prop without the composite component check
27
-
28
-
29
23
  return (0, _filterNodeByType.filterNodeByType)(element, _reactNative.TextInput) || (0, _filterNodeByType.filterNodeByType)(element, 'TextInput');
30
24
  };
31
-
32
25
  const isTouchResponder = element => {
33
26
  if (!(0, _componentTree.isHostElement)(element)) return false;
34
27
  return !!element?.props.onStartShouldSetResponder || isTextInput(element);
35
28
  };
36
-
37
29
  const isPointerEventEnabled = (element, isParent) => {
38
30
  const parentCondition = isParent ? element?.props.pointerEvents === 'box-only' : element?.props.pointerEvents === 'box-none';
39
-
40
31
  if (element?.props.pointerEvents === 'none' || parentCondition) {
41
32
  return false;
42
33
  }
43
-
44
34
  if (!element?.parent) return true;
45
35
  return isPointerEventEnabled(element.parent, true);
46
36
  };
47
-
48
37
  const isTouchEvent = eventName => {
49
38
  return eventName === 'press';
50
39
  };
51
-
52
40
  const isEventEnabled = (element, touchResponder, eventName) => {
53
41
  if (isTextInput(element)) return element?.props.editable !== false;
54
42
  if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;
@@ -57,57 +45,41 @@ const isEventEnabled = (element, touchResponder, eventName) => {
57
45
  if (touchStart || touchMove) return true;
58
46
  return touchStart === undefined && touchMove === undefined;
59
47
  };
60
-
61
48
  const findEventHandler = (element, eventName, callsite, nearestTouchResponder) => {
62
49
  const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
63
50
  const handler = getEventHandler(element, eventName);
64
51
  if (handler && isEventEnabled(element, touchResponder, eventName)) return handler;
65
-
66
52
  if (element.parent === null || element.parent.parent === null) {
67
53
  return null;
68
54
  }
69
-
70
55
  return findEventHandler(element.parent, eventName, callsite, touchResponder);
71
56
  };
72
-
73
57
  const getEventHandler = (element, eventName) => {
74
58
  const eventHandlerName = toEventHandlerName(eventName);
75
-
76
59
  if (typeof element.props[eventHandlerName] === 'function') {
77
60
  return element.props[eventHandlerName];
78
61
  }
79
-
80
62
  if (typeof element.props[eventName] === 'function') {
81
63
  return element.props[eventName];
82
64
  }
83
-
84
65
  return undefined;
85
66
  };
86
-
87
67
  const invokeEvent = (element, eventName, callsite, ...data) => {
88
68
  const handler = findEventHandler(element, eventName, callsite);
89
-
90
69
  if (!handler) {
91
70
  return;
92
71
  }
93
-
94
72
  let returnValue;
95
73
  (0, _act.default)(() => {
96
74
  returnValue = handler(...data);
97
75
  });
98
76
  return returnValue;
99
77
  };
100
-
101
78
  const toEventHandlerName = eventName => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
102
-
103
79
  const pressHandler = (element, ...data) => invokeEvent(element, 'press', pressHandler, ...data);
104
-
105
80
  const changeTextHandler = (element, ...data) => invokeEvent(element, 'changeText', changeTextHandler, ...data);
106
-
107
81
  const scrollHandler = (element, ...data) => invokeEvent(element, 'scroll', scrollHandler, ...data);
108
-
109
82
  const fireEvent = (element, eventName, ...data) => invokeEvent(element, eventName, fireEvent, ...data);
110
-
111
83
  fireEvent.press = pressHandler;
112
84
  fireEvent.changeText = changeTextHandler;
113
85
  fireEvent.scroll = scrollHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"fireEvent.js","names":["isTextInput","element","filterNodeByType","TextInput","isTouchResponder","isHostElement","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isTouchEvent","eventName","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","callsite","nearestTouchResponder","handler","getEventHandler","eventHandlerName","toEventHandlerName","invokeEvent","data","returnValue","act","charAt","toUpperCase","slice","pressHandler","changeTextHandler","scrollHandler","fireEvent","press","changeText","scroll"],"sources":["../src/fireEvent.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { filterNodeByType } from './helpers/filterNodeByType';\n\ntype EventHandler = (...args: any) => unknown;\n\nconst isTextInput = (element?: ReactTestInstance) => {\n if (!element) {\n return false;\n }\n\n // We have to test if the element type is either the TextInput component\n // (which would if it is a composite component) or the string\n // TextInput (which would be true if it is a host component)\n // All queries but the one by testID return composite component and event\n // if all queries returned host components, since fireEvent bubbles up\n // it would trigger the parent prop without the composite component check\n return (\n filterNodeByType(element, TextInput) ||\n filterNodeByType(element, 'TextInput')\n );\n};\n\nconst isTouchResponder = (element?: ReactTestInstance) => {\n if (!isHostElement(element)) return false;\n\n return !!element?.props.onStartShouldSetResponder || isTextInput(element);\n};\n\nconst isPointerEventEnabled = (\n element?: ReactTestInstance,\n isParent?: boolean\n): boolean => {\n const parentCondition = isParent\n ? element?.props.pointerEvents === 'box-only'\n : element?.props.pointerEvents === 'box-none';\n\n if (element?.props.pointerEvents === 'none' || parentCondition) {\n return false;\n }\n\n if (!element?.parent) return true;\n\n return isPointerEventEnabled(element.parent, true);\n};\n\nconst isTouchEvent = (eventName?: string) => {\n return eventName === 'press';\n};\n\nconst isEventEnabled = (\n element?: ReactTestInstance,\n touchResponder?: ReactTestInstance,\n eventName?: string\n) => {\n if (isTextInput(element)) return element?.props.editable !== false;\n if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;\n\n const touchStart = touchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();\n\n if (touchStart || touchMove) return true;\n\n return touchStart === undefined && touchMove === undefined;\n};\n\nconst findEventHandler = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\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, touchResponder, eventName))\n return handler;\n\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, callsite, touchResponder);\n};\n\nconst getEventHandler = (\n element: ReactTestInstance,\n eventName: string\n): EventHandler | undefined => {\n const eventHandlerName = toEventHandlerName(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\nconst invokeEvent = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\n ...data: Array<any>\n) => {\n const handler = findEventHandler(element, eventName, callsite);\n\n if (!handler) {\n return;\n }\n\n let returnValue;\n\n act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n};\n\nconst toEventHandlerName = (eventName: string) =>\n `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n\nconst pressHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'press', pressHandler, ...data);\nconst changeTextHandler = (\n element: ReactTestInstance,\n ...data: Array<any>\n): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);\nconst scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'scroll', scrollHandler, ...data);\n\nconst fireEvent = (\n element: ReactTestInstance,\n eventName: string,\n ...data: Array<any>\n): void => invokeEvent(element, eventName, fireEvent, ...data);\n\nfireEvent.press = pressHandler;\nfireEvent.changeText = changeTextHandler;\nfireEvent.scroll = scrollHandler;\n\nexport default fireEvent;\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;AAIA,MAAMA,WAAW,GAAIC,OAAD,IAAiC;EACnD,IAAI,CAACA,OAAL,EAAc;IACZ,OAAO,KAAP;EACD,CAHkD,CAKnD;EACA;EACA;EACA;EACA;EACA;;;EACA,OACE,IAAAC,kCAAA,EAAiBD,OAAjB,EAA0BE,sBAA1B,KACA,IAA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","filterNodeByType","TextInput","isTouchResponder","isHostElement","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isTouchEvent","eventName","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","callsite","nearestTouchResponder","handler","getEventHandler","eventHandlerName","toEventHandlerName","invokeEvent","data","returnValue","act","charAt","toUpperCase","slice","pressHandler","changeTextHandler","scrollHandler","fireEvent","press","changeText","scroll"],"sources":["../src/fireEvent.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { filterNodeByType } from './helpers/filterNodeByType';\n\ntype EventHandler = (...args: any) => unknown;\n\nconst isTextInput = (element?: ReactTestInstance) => {\n if (!element) {\n return false;\n }\n\n // We have to test if the element type is either the TextInput component\n // (which would if it is a composite component) or the string\n // TextInput (which would be true if it is a host component)\n // All queries but the one by testID return composite component and event\n // if all queries returned host components, since fireEvent bubbles up\n // it would trigger the parent prop without the composite component check\n return (\n filterNodeByType(element, TextInput) ||\n filterNodeByType(element, 'TextInput')\n );\n};\n\nconst isTouchResponder = (element?: ReactTestInstance) => {\n if (!isHostElement(element)) return false;\n\n return !!element?.props.onStartShouldSetResponder || isTextInput(element);\n};\n\nconst isPointerEventEnabled = (\n element?: ReactTestInstance,\n isParent?: boolean\n): boolean => {\n const parentCondition = isParent\n ? element?.props.pointerEvents === 'box-only'\n : element?.props.pointerEvents === 'box-none';\n\n if (element?.props.pointerEvents === 'none' || parentCondition) {\n return false;\n }\n\n if (!element?.parent) return true;\n\n return isPointerEventEnabled(element.parent, true);\n};\n\nconst isTouchEvent = (eventName?: string) => {\n return eventName === 'press';\n};\n\nconst isEventEnabled = (\n element?: ReactTestInstance,\n touchResponder?: ReactTestInstance,\n eventName?: string\n) => {\n if (isTextInput(element)) return element?.props.editable !== false;\n if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;\n\n const touchStart = touchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();\n\n if (touchStart || touchMove) return true;\n\n return touchStart === undefined && touchMove === undefined;\n};\n\nconst findEventHandler = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\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, touchResponder, eventName))\n return handler;\n\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, callsite, touchResponder);\n};\n\nconst getEventHandler = (\n element: ReactTestInstance,\n eventName: string\n): EventHandler | undefined => {\n const eventHandlerName = toEventHandlerName(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\nconst invokeEvent = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\n ...data: Array<any>\n) => {\n const handler = findEventHandler(element, eventName, callsite);\n\n if (!handler) {\n return;\n }\n\n let returnValue;\n\n act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n};\n\nconst toEventHandlerName = (eventName: string) =>\n `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n\nconst pressHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'press', pressHandler, ...data);\nconst changeTextHandler = (\n element: ReactTestInstance,\n ...data: Array<any>\n): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);\nconst scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'scroll', scrollHandler, ...data);\n\nconst fireEvent = (\n element: ReactTestInstance,\n eventName: string,\n ...data: Array<any>\n): void => invokeEvent(element, eventName, fireEvent, ...data);\n\nfireEvent.press = pressHandler;\nfireEvent.changeText = changeTextHandler;\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AACC,KAAK,GAAGJ,YAAY;AAC9BG,SAAS,CAACE,UAAU,GAAGJ,iBAAiB;AACxCE,SAAS,CAACG,MAAM,GAAGJ,aAAa;AAAC,eAElBC,SAAS;AAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.flushMicroTasks = flushMicroTasks;
7
-
8
7
  var _timers = require("./helpers/timers");
9
-
10
8
  function flushMicroTasks() {
11
9
  return {
12
10
  // using "thenable" instead of a Promise, because otherwise it breaks when
@@ -14,7 +12,6 @@ function flushMicroTasks() {
14
12
  then(resolve) {
15
13
  (0, _timers.setImmediate)(resolve);
16
14
  }
17
-
18
15
  };
19
16
  }
20
17
  //# sourceMappingURL=flushMicroTasks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flushMicroTasks.js","names":["flushMicroTasks","then","resolve","setImmediate"],"sources":["../src/flushMicroTasks.ts"],"sourcesContent":["import { setImmediate } from './helpers/timers';\n\ntype Thenable<T> = { then: (callback: () => T) => unknown };\n\nexport function flushMicroTasks<T>(): Thenable<T> {\n return {\n // using \"thenable\" instead of a Promise, because otherwise it breaks when\n // using \"modern\" fake timers\n then(resolve) {\n setImmediate(resolve);\n },\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAIO,SAASA,eAAT,GAA2C;EAChD,OAAO;IACL;IACA;IACAC,IAAI,CAACC,OAAD,EAAU;MACZ,IAAAC,oBAAA,EAAaD,OAAb;IACD;;EALI,CAAP;AAOD"}
1
+ {"version":3,"file":"flushMicroTasks.js","names":["flushMicroTasks","then","resolve","setImmediate"],"sources":["../src/flushMicroTasks.ts"],"sourcesContent":["import { setImmediate } from './helpers/timers';\n\ntype Thenable<T> = { then: (callback: () => T) => unknown };\n\nexport function flushMicroTasks<T>(): Thenable<T> {\n return {\n // using \"thenable\" instead of a Promise, because otherwise it breaks when\n // using \"modern\" fake timers\n then(resolve) {\n setImmediate(resolve);\n },\n };\n}\n"],"mappings":";;;;;;AAAA;AAIO,SAASA,eAAe,GAAmB;EAChD,OAAO;IACL;IACA;IACAC,IAAI,CAACC,OAAO,EAAE;MACZ,IAAAC,oBAAY,EAACD,OAAO,CAAC;IACvB;EACF,CAAC;AACH"}
@@ -1,2 +1,5 @@
1
+ import { AccessibilityState } from 'react-native';
1
2
  import { ReactTestInstance } from 'react-test-renderer';
3
+ export declare type AccessibilityStateKey = keyof AccessibilityState;
4
+ export declare const accessibilityStateKeys: AccessibilityStateKey[];
2
5
  export declare function isInaccessible(element: ReactTestInstance | null): boolean;
@@ -3,58 +3,52 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.accessibilityStateKeys = void 0;
6
7
  exports.isInaccessible = isInaccessible;
7
-
8
8
  var _reactNative = require("react-native");
9
-
10
9
  var _componentTree = require("./component-tree");
11
-
10
+ const accessibilityStateKeys = ['disabled', 'selected', 'checked', 'busy', 'expanded'];
11
+ exports.accessibilityStateKeys = accessibilityStateKeys;
12
12
  function isInaccessible(element) {
13
13
  if (element == null) {
14
14
  return true;
15
15
  }
16
-
17
16
  let current = element;
18
-
19
17
  while (current) {
20
18
  if (isSubtreeInaccessible(current)) {
21
19
  return true;
22
20
  }
23
-
24
21
  current = current.parent;
25
22
  }
26
-
27
23
  return false;
28
24
  }
29
-
30
25
  function isSubtreeInaccessible(element) {
31
26
  if (element == null) {
32
27
  return true;
33
- } // iOS: accessibilityElementsHidden
34
- // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios
35
-
28
+ }
36
29
 
30
+ // iOS: accessibilityElementsHidden
31
+ // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios
37
32
  if (element.props.accessibilityElementsHidden) {
38
33
  return true;
39
- } // Android: importantForAccessibility
40
- // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android
41
-
34
+ }
42
35
 
36
+ // Android: importantForAccessibility
37
+ // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android
43
38
  if (element.props.importantForAccessibility === 'no-hide-descendants') {
44
39
  return true;
45
- } // Note that `opacity: 0` is not threated as inassessible on iOS
46
-
40
+ }
47
41
 
42
+ // Note that `opacity: 0` is not threated as inassessible on iOS
48
43
  const flatStyle = _reactNative.StyleSheet.flatten(element.props.style) ?? {};
49
- if (flatStyle.display === 'none') return true; // iOS: accessibilityViewIsModal
50
- // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios
44
+ if (flatStyle.display === 'none') return true;
51
45
 
46
+ // iOS: accessibilityViewIsModal
47
+ // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios
52
48
  const hostSiblings = (0, _componentTree.getHostSiblings)(element);
53
-
54
49
  if (hostSiblings.some(sibling => sibling.props.accessibilityViewIsModal)) {
55
50
  return true;
56
51
  }
57
-
58
52
  return false;
59
53
  }
60
54
  //# sourceMappingURL=accessiblity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessiblity.js","names":["isInaccessible","element","current","isSubtreeInaccessible","parent","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import { StyleSheet } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\n\nexport function isInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n if (isSubtreeInaccessible(current)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\nfunction isSubtreeInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\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 threated as inassessible 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"],"mappings":";;;;;;;AAAA;;AAEA;;AAEO,SAASA,cAAT,CAAwBC,OAAxB,EAAoE;EACzE,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,IAAP;EACD;;EAED,IAAIC,OAAiC,GAAGD,OAAxC;;EACA,OAAOC,OAAP,EAAgB;IACd,IAAIC,qBAAqB,CAACD,OAAD,CAAzB,EAAoC;MAClC,OAAO,IAAP;IACD;;IAEDA,OAAO,GAAGA,OAAO,CAACE,MAAlB;EACD;;EAED,OAAO,KAAP;AACD;;AAED,SAASD,qBAAT,CAA+BF,OAA/B,EAA2E;EACzE,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,IAAP;EACD,CAHwE,CAKzE;EACA;;;EACA,IAAIA,OAAO,CAACI,KAAR,CAAcC,2BAAlB,EAA+C;IAC7C,OAAO,IAAP;EACD,CATwE,CAWzE;EACA;;;EACA,IAAIL,OAAO,CAACI,KAAR,CAAcE,yBAAd,KAA4C,qBAAhD,EAAuE;IACrE,OAAO,IAAP;EACD,CAfwE,CAiBzE;;;EACA,MAAMC,SAAS,GAAGC,uBAAA,CAAWC,OAAX,CAAmBT,OAAO,CAACI,KAAR,CAAcM,KAAjC,KAA2C,EAA7D;EACA,IAAIH,SAAS,CAACI,OAAV,KAAsB,MAA1B,EAAkC,OAAO,IAAP,CAnBuC,CAqBzE;EACA;;EACA,MAAMC,YAAY,GAAG,IAAAC,8BAAA,EAAgBb,OAAhB,CAArB;;EACA,IAAIY,YAAY,CAACE,IAAb,CAAmBC,OAAD,IAAaA,OAAO,CAACX,KAAR,CAAcY,wBAA7C,CAAJ,EAA4E;IAC1E,OAAO,IAAP;EACD;;EAED,OAAO,KAAP;AACD"}
1
+ {"version":3,"file":"accessiblity.js","names":["accessibilityStateKeys","isInaccessible","element","current","isSubtreeInaccessible","parent","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import { AccessibilityState, StyleSheet } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\n\nexport type AccessibilityStateKey = keyof AccessibilityState;\n\nexport const accessibilityStateKeys: AccessibilityStateKey[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport function isInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n if (isSubtreeInaccessible(current)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\nfunction isSubtreeInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\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 threated as inassessible 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"],"mappings":";;;;;;;AAAA;AAEA;AAIO,MAAMA,sBAA+C,GAAG,CAC7D,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAAC;AAEK,SAASC,cAAc,CAACC,OAAiC,EAAW;EACzE,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIC,OAAiC,GAAGD,OAAO;EAC/C,OAAOC,OAAO,EAAE;IACd,IAAIC,qBAAqB,CAACD,OAAO,CAAC,EAAE;MAClC,OAAO,IAAI;IACb;IAEAA,OAAO,GAAGA,OAAO,CAACE,MAAM;EAC1B;EAEA,OAAO,KAAK;AACd;AAEA,SAASD,qBAAqB,CAACF,OAAiC,EAAW;EACzE,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;;EAEA;EACA;EACA,IAAIA,OAAO,CAACI,KAAK,CAACC,2BAA2B,EAAE;IAC7C,OAAO,IAAI;EACb;;EAEA;EACA;EACA,IAAIL,OAAO,CAACI,KAAK,CAACE,yBAAyB,KAAK,qBAAqB,EAAE;IACrE,OAAO,IAAI;EACb;;EAEA;EACA,MAAMC,SAAS,GAAGC,uBAAU,CAACC,OAAO,CAACT,OAAO,CAACI,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,EAACb,OAAO,CAAC;EAC7C,IAAIY,YAAY,CAACE,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACX,KAAK,CAACY,wBAAwB,CAAC,EAAE;IAC1E,OAAO,IAAI;EACb;EAEA,OAAO,KAAK;AACd"}
@@ -11,7 +11,6 @@ exports.getHostSelves = getHostSelves;
11
11
  exports.getHostSiblings = getHostSiblings;
12
12
  exports.isHostElement = isHostElement;
13
13
  exports.isHostElementForType = isHostElementForType;
14
-
15
14
  /**
16
15
  * Checks if the given element is a host element.
17
16
  * @param element The element to check.
@@ -19,46 +18,38 @@ exports.isHostElementForType = isHostElementForType;
19
18
  function isHostElement(element) {
20
19
  return typeof element?.type === 'string';
21
20
  }
21
+
22
22
  /**
23
23
  * Returns first host ancestor for given element.
24
24
  * @param element The element start traversing from.
25
25
  */
26
-
27
-
28
26
  function getHostParent(element) {
29
27
  if (element == null) {
30
28
  return null;
31
29
  }
32
-
33
30
  let current = element.parent;
34
-
35
31
  while (current) {
36
32
  if (isHostElement(current)) {
37
33
  return current;
38
34
  }
39
-
40
35
  current = current.parent;
41
36
  }
42
-
43
37
  return null;
44
38
  }
39
+
45
40
  /**
46
41
  * Returns host children for given element.
47
42
  * @param element The element start traversing from.
48
43
  */
49
-
50
-
51
44
  function getHostChildren(element) {
52
45
  if (element == null) {
53
46
  return [];
54
47
  }
55
-
56
48
  const hostChildren = [];
57
49
  element.children.forEach(child => {
58
50
  if (typeof child !== 'object') {
59
51
  return;
60
52
  }
61
-
62
53
  if (isHostElement(child)) {
63
54
  hostChildren.push(child);
64
55
  } else {
@@ -67,6 +58,7 @@ function getHostChildren(element) {
67
58
  });
68
59
  return hostChildren;
69
60
  }
61
+
70
62
  /**
71
63
  * Return a single host element that represent the passed host or composite element.
72
64
  *
@@ -75,21 +67,17 @@ function getHostChildren(element) {
75
67
  * @returns If the passed element is a host element, it will return itself, if the passed element is a composite
76
68
  * element, it will return a single host descendant.
77
69
  */
78
-
79
-
80
70
  function getHostSelf(element) {
81
71
  const hostSelves = getHostSelves(element);
82
-
83
72
  if (hostSelves.length === 0) {
84
73
  throw new Error(`Expected exactly one host element, but found none.`);
85
74
  }
86
-
87
75
  if (hostSelves.length > 1) {
88
76
  throw new Error(`Expected exactly one host element, but found ${hostSelves.length}.`);
89
77
  }
90
-
91
78
  return hostSelves[0];
92
79
  }
80
+
93
81
  /**
94
82
  * Return the array of host elements that represent the passed element.
95
83
  *
@@ -97,46 +85,37 @@ function getHostSelf(element) {
97
85
  * @returns If the passed element is a host element, it will return an array containing only that element,
98
86
  * if the passed element is a composite element, it will return an array containing its host children (zero, one or many).
99
87
  */
100
-
101
-
102
88
  function getHostSelves(element) {
103
89
  return typeof element?.type === 'string' ? [element] : getHostChildren(element);
104
90
  }
91
+
105
92
  /**
106
93
  * Returns host siblings for given element.
107
94
  * @param element The element start traversing from.
108
95
  */
109
-
110
-
111
96
  function getHostSiblings(element) {
112
97
  const hostParent = getHostParent(element);
113
98
  const hostSelves = getHostSelves(element);
114
99
  return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
115
100
  }
116
-
117
101
  function getCompositeParentOfType(element, type) {
118
102
  let current = element.parent;
119
-
120
103
  while (!isHostElement(current)) {
121
104
  // We're at the root of the tree
122
105
  if (!current) {
123
106
  return null;
124
107
  }
125
-
126
108
  if (current.type === type) {
127
109
  return current;
128
110
  }
129
-
130
111
  current = current.parent;
131
112
  }
132
-
133
113
  return null;
134
114
  }
115
+
135
116
  /**
136
117
  * Note: this function should be generally used for core React Native types like `View`, `Text`, `TextInput`, etc.
137
118
  */
138
-
139
-
140
119
  function isHostElementForType(element, type) {
141
120
  // Not a host element
142
121
  if (!isHostElement(element)) return false;