@testing-library/react-native 9.0.0 → 10.0.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 (121) hide show
  1. package/README.md +2 -2
  2. package/build/act.d.ts +3 -0
  3. package/build/act.js +2 -1
  4. package/build/act.js.map +1 -0
  5. package/build/cleanup.d.ts +5 -0
  6. package/build/cleanup.js +3 -2
  7. package/build/cleanup.js.map +1 -0
  8. package/build/fireEvent.d.ts +8 -0
  9. package/build/fireEvent.js +2 -1
  10. package/build/fireEvent.js.map +1 -0
  11. package/build/flushMicroTasks.d.ts +5 -0
  12. package/build/flushMicroTasks.js +2 -12
  13. package/build/flushMicroTasks.js.map +1 -0
  14. package/build/helpers/debugDeep.d.ts +5 -0
  15. package/build/helpers/debugDeep.js +4 -1
  16. package/build/helpers/debugDeep.js.map +1 -0
  17. package/build/helpers/debugShallow.d.ts +6 -0
  18. package/build/helpers/debugShallow.js +4 -7
  19. package/build/helpers/debugShallow.js.map +1 -0
  20. package/build/helpers/errors.d.ts +10 -0
  21. package/build/helpers/errors.js +29 -9
  22. package/build/helpers/errors.js.map +1 -0
  23. package/build/helpers/filterNodeByType.d.ts +3 -0
  24. package/build/helpers/filterNodeByType.js +2 -1
  25. package/build/helpers/filterNodeByType.js.map +1 -0
  26. package/build/helpers/format.d.ts +3 -0
  27. package/build/helpers/format.js +4 -3
  28. package/build/helpers/format.js.map +1 -0
  29. package/build/helpers/timers.d.ts +6 -0
  30. package/build/helpers/timers.js +9 -6
  31. package/build/helpers/timers.js.map +1 -0
  32. package/build/index.d.ts +1 -0
  33. package/build/index.flow.js +394 -0
  34. package/build/index.js +2 -1
  35. package/build/index.js.map +1 -0
  36. package/build/matches.d.ts +9 -0
  37. package/build/matches.js +3 -2
  38. package/build/matches.js.map +1 -0
  39. package/build/{pure.js.flow → pure.d.ts} +4 -8
  40. package/build/pure.js +14 -31
  41. package/build/pure.js.map +1 -0
  42. package/build/queries/a11yAPI.d.ts +66 -0
  43. package/build/{helpers → queries}/a11yAPI.js +16 -15
  44. package/build/queries/a11yAPI.js.map +1 -0
  45. package/build/queries/displayValue.d.ts +13 -0
  46. package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -17
  47. package/build/queries/displayValue.js.map +1 -0
  48. package/build/queries/makeA11yQuery.d.ts +13 -0
  49. package/build/{helpers → queries}/makeA11yQuery.js +3 -2
  50. package/build/queries/makeA11yQuery.js.map +1 -0
  51. package/build/queries/makeQueries.d.ts +19 -0
  52. package/build/{helpers → queries}/makeQueries.js +23 -19
  53. package/build/queries/makeQueries.js.map +1 -0
  54. package/build/queries/placeholderText.d.ts +13 -0
  55. package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -17
  56. package/build/queries/placeholderText.js.map +1 -0
  57. package/build/queries/testId.d.ts +13 -0
  58. package/build/{helpers/byTestId.js → queries/testId.js} +19 -13
  59. package/build/queries/testId.js.map +1 -0
  60. package/build/queries/text.d.ts +17 -0
  61. package/build/{helpers/byText.js → queries/text.js} +31 -23
  62. package/build/queries/text.js.map +1 -0
  63. package/build/queries/unsafeProps.d.ts +16 -0
  64. package/build/queries/unsafeProps.js +58 -0
  65. package/build/queries/unsafeProps.js.map +1 -0
  66. package/build/queries/unsafeType.d.ts +9 -0
  67. package/build/queries/unsafeType.js +54 -0
  68. package/build/queries/unsafeType.js.map +1 -0
  69. package/build/render.d.ts +135 -0
  70. package/build/render.js +16 -21
  71. package/build/render.js.map +1 -0
  72. package/build/renderHook.d.ts +17 -0
  73. package/build/renderHook.js +57 -0
  74. package/build/renderHook.js.map +1 -0
  75. package/build/shallow.d.ts +8 -0
  76. package/build/shallow.js +3 -9
  77. package/build/shallow.js.map +1 -0
  78. package/build/waitFor.d.ts +8 -0
  79. package/build/waitFor.js +32 -23
  80. package/build/waitFor.js.map +1 -0
  81. package/build/waitForElementToBeRemoved.d.ts +2 -0
  82. package/build/waitForElementToBeRemoved.js +2 -1
  83. package/build/waitForElementToBeRemoved.js.map +1 -0
  84. package/build/within.d.ts +117 -0
  85. package/build/within.js +19 -9
  86. package/build/within.js.map +1 -0
  87. package/package.json +24 -14
  88. package/typings/index.flow.js +394 -0
  89. package/build/act.js.flow +0 -9
  90. package/build/cleanup.js.flow +0 -13
  91. package/build/fireEvent.js.flow +0 -127
  92. package/build/flushMicroTasks.js.flow +0 -23
  93. package/build/helpers/a11yAPI.js.flow +0 -241
  94. package/build/helpers/byDisplayValue.js.flow +0 -66
  95. package/build/helpers/byPlaceholderText.js.flow +0 -62
  96. package/build/helpers/byTestId.js.flow +0 -50
  97. package/build/helpers/byText.js.flow +0 -104
  98. package/build/helpers/debugDeep.js.flow +0 -16
  99. package/build/helpers/debugShallow.js.flow +0 -20
  100. package/build/helpers/errors.js.flow +0 -82
  101. package/build/helpers/filterNodeByType.js.flow +0 -1
  102. package/build/helpers/findByAPI.js +0 -32
  103. package/build/helpers/findByAPI.js.flow +0 -76
  104. package/build/helpers/format.js.flow +0 -10
  105. package/build/helpers/getByAPI.js +0 -98
  106. package/build/helpers/getByAPI.js.flow +0 -157
  107. package/build/helpers/makeA11yQuery.js.flow +0 -98
  108. package/build/helpers/makeQueries.js.flow +0 -165
  109. package/build/helpers/queryByAPI.js +0 -92
  110. package/build/helpers/queryByAPI.js.flow +0 -166
  111. package/build/helpers/timers.js.flow +0 -88
  112. package/build/index.js.flow +0 -18
  113. package/build/matches.js.flow +0 -41
  114. package/build/render.js.flow +0 -109
  115. package/build/shallow.js.flow +0 -26
  116. package/build/types.flow.js +0 -1
  117. package/build/types.flow.js.flow +0 -59
  118. package/build/waitFor.js.flow +0 -221
  119. package/build/waitForElementToBeRemoved.js.flow +0 -42
  120. package/build/within.js.flow +0 -18
  121. package/typings/index.d.ts +0 -432
package/README.md CHANGED
@@ -109,11 +109,11 @@ test('form submits two answers', () => {
109
109
  const allQuestions = ['q1', 'q2'];
110
110
  const mockFn = jest.fn();
111
111
 
112
- const { getAllByA11yLabel, getByText } = render(
112
+ const { getAllByLabelText, getByText } = render(
113
113
  <QuestionsBoard questions={allQuestions} onSubmit={mockFn} />
114
114
  );
115
115
 
116
- const answerInputs = getAllByA11yLabel('answer input');
116
+ const answerInputs = getAllByLabelText('answer input');
117
117
 
118
118
  fireEvent.changeText(answerInputs[0], 'a1');
119
119
  fireEvent.changeText(answerInputs[1], 'a2');
package/build/act.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { act } from 'react-test-renderer';
2
+ declare const _default: typeof act;
3
+ export default _default;
package/build/act.js CHANGED
@@ -13,4 +13,5 @@ const actMock = callback => {
13
13
 
14
14
  var _default = _reactTestRenderer.act || actMock;
15
15
 
16
- exports.default = _default;
16
+ exports.default = _default;
17
+ //# sourceMappingURL=act.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/act.ts"],"names":["actMock","callback","act"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,OAAO,GAAIC,QAAD,IAA0B;AACxCA,EAAAA,QAAQ;AACT,CAFD;;eAIeC,0BAAOF,O","sourcesContent":["import { act } from 'react-test-renderer';\n\nconst actMock = (callback: () => void) => {\n callback();\n};\n\nexport default act || actMock;\n"],"file":"act.js"}
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ declare type CleanUpFunction = (nextElement?: React.ReactElement<any>) => void;
3
+ export default function cleanup(): void;
4
+ export declare function addToCleanupQueue(fn: CleanUpFunction): void;
5
+ export {};
package/build/cleanup.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = cleanup;
7
6
  exports.addToCleanupQueue = addToCleanupQueue;
7
+ exports.default = cleanup;
8
8
  let cleanupQueue = new Set();
9
9
 
10
10
  function cleanup() {
@@ -14,4 +14,5 @@ function cleanup() {
14
14
 
15
15
  function addToCleanupQueue(fn) {
16
16
  cleanupQueue.add(fn);
17
- }
17
+ }
18
+ //# sourceMappingURL=cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cleanup.ts"],"names":["cleanupQueue","Set","cleanup","forEach","fn","clear","addToCleanupQueue","add"],"mappings":";;;;;;;AAGA,IAAIA,YAAY,GAAG,IAAIC,GAAJ,EAAnB;;AAEe,SAASC,OAAT,GAAmB;AAChCF,EAAAA,YAAY,CAACG,OAAb,CAAsBC,EAAD,IAAQA,EAAE,EAA/B;AACAJ,EAAAA,YAAY,CAACK,KAAb;AACD;;AAEM,SAASC,iBAAT,CAA2BF,EAA3B,EAAgD;AACrDJ,EAAAA,YAAY,CAACO,GAAb,CAAiBH,EAAjB;AACD","sourcesContent":["import * as React from 'react';\n\ntype CleanUpFunction = (nextElement?: React.ReactElement<any>) => void;\nlet cleanupQueue = new Set<CleanUpFunction>();\n\nexport default function cleanup() {\n cleanupQueue.forEach((fn) => fn());\n cleanupQueue.clear();\n}\n\nexport function addToCleanupQueue(fn: CleanUpFunction) {\n cleanupQueue.add(fn);\n}\n"],"file":"cleanup.js"}
@@ -0,0 +1,8 @@
1
+ import { ReactTestInstance } from 'react-test-renderer';
2
+ declare const fireEvent: {
3
+ (element: ReactTestInstance, eventName: string, ...data: Array<any>): void;
4
+ press: (element: ReactTestInstance, ...data: Array<any>) => void;
5
+ changeText: (element: ReactTestInstance, ...data: Array<any>) => void;
6
+ scroll: (element: ReactTestInstance, ...data: Array<any>) => void;
7
+ };
8
+ export default fireEvent;
@@ -102,4 +102,5 @@ fireEvent.press = pressHandler;
102
102
  fireEvent.changeText = changeTextHandler;
103
103
  fireEvent.scroll = scrollHandler;
104
104
  var _default = fireEvent;
105
- exports.default = _default;
105
+ exports.default = _default;
106
+ //# sourceMappingURL=fireEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fireEvent.ts"],"names":["isHostElement","element","type","isTextInput","TextInput","require","isTouchResponder","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","eventName","callsite","nearestTouchResponder","handler","getEventHandler","eventHandlerName","toEventHandlerName","invokeEvent","data","returnValue","charAt","toUpperCase","slice","pressHandler","changeTextHandler","scrollHandler","fireEvent","press","changeText","scroll"],"mappings":";;;;;;;AACA;;;;AAIA,MAAMA,aAAa,GAAIC,OAAD,IAAiC;AACrD,SAAO,QAAOA,OAAP,aAAOA,OAAP,uBAAOA,OAAO,CAAEC,IAAhB,MAAyB,QAAhC;AACD,CAFD;;AAIA,MAAMC,WAAW,GAAIF,OAAD,IAAiC;AACnD,QAAM;AAAEG,IAAAA;AAAF,MAAgBC,OAAO,CAAC,cAAD,CAA7B;;AACA,SAAO,CAAAJ,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,IAAT,MAAkBE,SAAzB;AACD,CAHD;;AAKA,MAAME,gBAAgB,GAAIL,OAAD,IAAiC;AACxD,MAAI,CAACD,aAAa,CAACC,OAAD,CAAlB,EAA6B,OAAO,KAAP;AAE7B,SAAO,CAAC,EAACA,OAAD,aAACA,OAAD,eAACA,OAAO,CAAEM,KAAT,CAAeC,yBAAhB,CAAD,IAA8CL,WAAW,CAACF,OAAD,CAAhE;AACD,CAJD;;AAMA,MAAMQ,qBAAqB,GAAG,CAC5BR,OAD4B,EAE5BS,QAF4B,KAGhB;AACZ,QAAMC,eAAe,GAAGD,QAAQ,GAC5B,CAAAT,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEM,KAAT,CAAeK,aAAf,MAAiC,UADL,GAE5B,CAAAX,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEM,KAAT,CAAeK,aAAf,MAAiC,UAFrC;;AAIA,MAAI,CAAAX,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEM,KAAT,CAAeK,aAAf,MAAiC,MAAjC,IAA2CD,eAA/C,EAAgE;AAC9D,WAAO,KAAP;AACD;;AAED,MAAI,EAACV,OAAD,aAACA,OAAD,eAAC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GAAG,CACxBnC,OADwB,EAExB,GAAG6B,IAFqB,KAGfD,WAAW,CAAC5B,OAAD,EAAU,YAAV,EAAwBmC,iBAAxB,EAA2C,GAAGN,IAA9C,CAHtB;;AAIA,MAAMO,aAAa,GAAG,CAACpC,OAAD,EAA6B,GAAG6B,IAAhC,KACpBD,WAAW,CAAC5B,OAAD,EAAU,QAAV,EAAoBoC,aAApB,EAAmC,GAAGP,IAAtC,CADb;;AAGA,MAAMQ,SAAS,GAAG,CAChBrC,OADgB,EAEhBqB,SAFgB,EAGhB,GAAGQ,IAHa,KAIPD,WAAW,CAAC5B,OAAD,EAAUqB,SAAV,EAAqBgB,SAArB,EAAgC,GAAGR,IAAnC,CAJtB;;AAMAQ,SAAS,CAACC,KAAV,GAAkBJ,YAAlB;AACAG,SAAS,CAACE,UAAV,GAAuBJ,iBAAvB;AACAE,SAAS,CAACG,MAAV,GAAmBJ,aAAnB;eAEeC,S","sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from './act';\n\ntype EventHandler = (...args: any) => unknown;\n\nconst isHostElement = (element?: ReactTestInstance) => {\n return typeof element?.type === 'string';\n};\n\nconst isTextInput = (element?: ReactTestInstance) => {\n const { TextInput } = require('react-native');\n return element?.type === TextInput;\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 isEventEnabled = (\n element?: ReactTestInstance,\n touchResponder?: ReactTestInstance\n) => {\n if (isTextInput(element)) return element?.props.editable !== false;\n if (!isPointerEventEnabled(element)) 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)) 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"],"file":"fireEvent.js"}
@@ -0,0 +1,5 @@
1
+ declare type Thenable<T> = {
2
+ then: (callback: () => T) => unknown;
3
+ };
4
+ export declare function flushMicroTasks<T>(): Thenable<T>;
5
+ export {};
@@ -3,21 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = flushMicrotasksQueue;
7
6
  exports.flushMicroTasks = flushMicroTasks;
8
7
 
9
- var _errors = require("./helpers/errors");
10
-
11
8
  var _timers = require("./helpers/timers");
12
9
 
13
- /**
14
- * Wait for microtasks queue to flush
15
- */
16
- function flushMicrotasksQueue() {
17
- (0, _errors.printDeprecationWarning)('flushMicrotasksQueue');
18
- return flushMicroTasks();
19
- }
20
-
21
10
  function flushMicroTasks() {
22
11
  return {
23
12
  // using "thenable" instead of a Promise, because otherwise it breaks when
@@ -27,4 +16,5 @@ function flushMicroTasks() {
27
16
  }
28
17
 
29
18
  };
30
- }
19
+ }
20
+ //# sourceMappingURL=flushMicroTasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/flushMicroTasks.ts"],"names":["flushMicroTasks","then","resolve"],"mappings":";;;;;;;AAAA;;AAIO,SAASA,eAAT,GAA2C;AAChD,SAAO;AACL;AACA;AACAC,IAAAA,IAAI,CAACC,OAAD,EAAU;AACZ,gCAAaA,OAAb;AACD;;AALI,GAAP;AAOD","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"],"file":"flushMicroTasks.js"}
@@ -0,0 +1,5 @@
1
+ import type { ReactTestRendererJSON } from 'react-test-renderer';
2
+ /**
3
+ * Log pretty-printed deep test component instance
4
+ */
5
+ export default function debugDeep(instance: ReactTestRendererJSON | ReactTestRendererJSON[], message?: string): void;
@@ -14,8 +14,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  */
15
15
  function debugDeep(instance, message) {
16
16
  if (message) {
17
+ // eslint-disable-next-line no-console
17
18
  console.log(`${message}\n\n`, (0, _format.default)(instance));
18
19
  } else {
20
+ // eslint-disable-next-line no-console
19
21
  console.log((0, _format.default)(instance));
20
22
  }
21
- }
23
+ }
24
+ //# sourceMappingURL=debugDeep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/debugDeep.ts"],"names":["debugDeep","instance","message","console","log"],"mappings":";;;;;;;AACA;;;;AAEA;AACA;AACA;AACe,SAASA,SAAT,CACbC,QADa,EAEbC,OAFa,EAGb;AACA,MAAIA,OAAJ,EAAa;AACX;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAa,GAAEF,OAAQ,MAAvB,EAA8B,qBAAOD,QAAP,CAA9B;AACD,GAHD,MAGO;AACL;AACAE,IAAAA,OAAO,CAACC,GAAR,CAAY,qBAAOH,QAAP,CAAZ;AACD;AACF","sourcesContent":["import type { ReactTestRendererJSON } from 'react-test-renderer';\nimport format from './format';\n\n/**\n * Log pretty-printed deep test component instance\n */\nexport default function debugDeep(\n instance: ReactTestRendererJSON | ReactTestRendererJSON[],\n message?: string\n) {\n if (message) {\n // eslint-disable-next-line no-console\n console.log(`${message}\\n\\n`, format(instance));\n } else {\n // eslint-disable-next-line no-console\n console.log(format(instance));\n }\n}\n"],"file":"debugDeep.js"}
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ /**
4
+ * Log pretty-printed shallow test component instance
5
+ */
6
+ export default function debugShallow(instance: ReactTestInstance | React.ReactElement<any>, message?: string): void;
@@ -5,18 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = debugShallow;
7
7
 
8
- var React = _interopRequireWildcard(require("react"));
9
-
10
8
  var _shallow = require("../shallow");
11
9
 
12
10
  var _format = _interopRequireDefault(require("./format"));
13
11
 
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
17
-
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
19
-
20
14
  /**
21
15
  * Log pretty-printed shallow test component instance
22
16
  */
@@ -26,8 +20,11 @@ function debugShallow(instance, message) {
26
20
  } = (0, _shallow.shallowInternal)(instance);
27
21
 
28
22
  if (message) {
23
+ // eslint-disable-next-line no-console
29
24
  console.log(`${message}\n\n`, (0, _format.default)(output));
30
25
  } else {
26
+ // eslint-disable-next-line no-console
31
27
  console.log((0, _format.default)(output));
32
28
  }
33
- }
29
+ }
30
+ //# sourceMappingURL=debugShallow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/debugShallow.ts"],"names":["debugShallow","instance","message","output","console","log"],"mappings":";;;;;;;AAEA;;AACA;;;;AAEA;AACA;AACA;AACe,SAASA,YAAT,CACbC,QADa,EAEbC,OAFa,EAGb;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAa,8BAAgBF,QAAhB,CAAnB;;AAEA,MAAIC,OAAJ,EAAa;AACX;AACAE,IAAAA,OAAO,CAACC,GAAR,CAAa,GAAEH,OAAQ,MAAvB,EAA8B,qBAAOC,MAAP,CAA9B;AACD,GAHD,MAGO;AACL;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAY,qBAAOF,MAAP,CAAZ;AACD;AACF","sourcesContent":["import * as React from 'react';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { shallowInternal } from '../shallow';\nimport format from './format';\n\n/**\n * Log pretty-printed shallow test component instance\n */\nexport default function debugShallow(\n instance: ReactTestInstance | React.ReactElement<any>,\n message?: string\n) {\n const { output } = shallowInternal(instance);\n\n if (message) {\n // eslint-disable-next-line no-console\n console.log(`${message}\\n\\n`, format(output));\n } else {\n // eslint-disable-next-line no-console\n console.log(format(output));\n }\n}\n"],"file":"debugShallow.js"}
@@ -0,0 +1,10 @@
1
+ export declare class ErrorWithStack extends Error {
2
+ constructor(message: string | undefined, callsite: Function);
3
+ }
4
+ export declare const createLibraryNotSupportedError: (error: unknown) => Error;
5
+ export declare const prepareErrorMessage: (error: unknown, name?: string | undefined, value?: unknown) => string;
6
+ export declare const createQueryByError: (error: NonNullable<unknown>, callsite: Function) => null;
7
+ export declare function copyStackTrace(target: unknown, stackTraceSource: Error): void;
8
+ export declare function printDeprecationWarning(functionName: string): void;
9
+ export declare function throwRemovedFunctionError(functionName: string, docsRef: string): void;
10
+ export declare function throwRenamedFunctionError(functionName: string, newFunctionName: string): void;
@@ -3,11 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ErrorWithStack = void 0;
6
7
  exports.copyStackTrace = copyStackTrace;
8
+ exports.prepareErrorMessage = exports.createQueryByError = exports.createLibraryNotSupportedError = void 0;
7
9
  exports.printDeprecationWarning = printDeprecationWarning;
8
10
  exports.throwRemovedFunctionError = throwRemovedFunctionError;
9
11
  exports.throwRenamedFunctionError = throwRenamedFunctionError;
10
- exports.createQueryByError = exports.prepareErrorMessage = exports.createLibraryNotSupportedError = exports.ErrorWithStack = void 0;
11
12
 
12
13
  var _prettyFormat = _interopRequireDefault(require("pretty-format"));
13
14
 
@@ -26,13 +27,21 @@ class ErrorWithStack extends Error {
26
27
 
27
28
  exports.ErrorWithStack = ErrorWithStack;
28
29
 
29
- const createLibraryNotSupportedError = error => new Error(`Currently the only supported library to search by text is "react-native".\n\n${error.message}`);
30
+ const createLibraryNotSupportedError = error => new Error(`Currently the only supported library to search by text is "react-native".\n\n${error instanceof Error ? error.message : ''}`);
30
31
 
31
32
  exports.createLibraryNotSupportedError = createLibraryNotSupportedError;
32
33
 
33
34
  const prepareErrorMessage = (error, name, value) => {
34
- // Strip info about custom predicate
35
- let errorMessage = error.message.replace(/ matching custom predicate[^]*/gm, '');
35
+ let errorMessage;
36
+
37
+ if (error instanceof Error) {
38
+ // Strip info about custom predicate
39
+ errorMessage = error.message.replace(/ matching custom predicate[^]*/gm, '');
40
+ } else if (error && typeof error === 'object') {
41
+ errorMessage = error.toString();
42
+ } else {
43
+ errorMessage = 'Caught unknown error';
44
+ }
36
45
 
37
46
  if (name && value) {
38
47
  errorMessage += ` with ${name} ${(0, _prettyFormat.default)(value, {
@@ -46,17 +55,27 @@ const prepareErrorMessage = (error, name, value) => {
46
55
  exports.prepareErrorMessage = prepareErrorMessage;
47
56
 
48
57
  const createQueryByError = (error, callsite) => {
49
- if (error.message.includes('No instances found')) {
50
- return null;
58
+ var _toString, _ref;
59
+
60
+ if (error instanceof Error) {
61
+ if (error.message.includes('No instances found')) {
62
+ return null;
63
+ }
64
+
65
+ throw new ErrorWithStack(error.message, callsite);
51
66
  }
52
67
 
53
- throw new ErrorWithStack(error.message, callsite);
68
+ throw new ErrorWithStack( // generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that
69
+ // Converting as any with extra safe optional chaining will do the job just as well
70
+ `Query: caught unknown error type: ${typeof error}, value: ${error === null || error === void 0 ? void 0 : (_toString = (_ref = error).toString) === null || _toString === void 0 ? void 0 : _toString.call(_ref)}`, callsite);
54
71
  };
55
72
 
56
73
  exports.createQueryByError = createQueryByError;
57
74
 
58
75
  function copyStackTrace(target, stackTraceSource) {
59
- target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);
76
+ if (target instanceof Error && stackTraceSource.stack) {
77
+ target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);
78
+ }
60
79
  }
61
80
 
62
81
  const warned = {};
@@ -80,4 +99,5 @@ function throwRemovedFunctionError(functionName, docsRef) {
80
99
 
81
100
  function throwRenamedFunctionError(functionName, newFunctionName) {
82
101
  throw new ErrorWithStack(`The "${functionName}" function has been renamed to "${newFunctionName}". Please replace all occurrences.`, throwRenamedFunctionError);
83
- }
102
+ }
103
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/errors.ts"],"names":["ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","createLibraryNotSupportedError","error","prepareErrorMessage","name","value","errorMessage","replace","toString","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack","warned","printDeprecationWarning","functionName","console","warn","throwRemovedFunctionError","docsRef","throwRenamedFunctionError","newFunctionName"],"mappings":";;;;;;;;;;;;AAAA;;;;AAEO,MAAMA,cAAN,SAA6BC,KAA7B,CAAmC;AACxCC,EAAAA,WAAW,CAACC,OAAD,EAA8BC,QAA9B,EAAkD;AAC3D,UAAMD,OAAN;;AACA,QAAIF,KAAK,CAACI,iBAAV,EAA6B;AAC3BJ,MAAAA,KAAK,CAACI,iBAAN,CAAwB,IAAxB,EAA8BD,QAA9B;AACD;AACF;;AANuC;;;;AASnC,MAAME,8BAA8B,GAAIC,KAAD,IAC5C,IAAIN,KAAJ,CACG,gFACCM,KAAK,YAAYN,KAAjB,GAAyBM,KAAK,CAACJ,OAA/B,GAAyC,EAC1C,EAHH,CADK;;;;AAOA,MAAMK,mBAAmB,GAAG,CAGjCD,KAHiC,EAIjCE,IAJiC,EAKjCC,KALiC,KAMtB;AACX,MAAIC,YAAJ;;AACA,MAAIJ,KAAK,YAAYN,KAArB,EAA4B;AAC1B;AACAU,IAA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MAA2C,GAAG,EAApD;;AAEO,SAASC,uBAAT,CAAiCC,YAAjC,EAAuD;AAC5D,MAAIF,MAAM,CAACE,YAAD,CAAV,EAA0B;AACxB;AACD,GAH2D,CAK5D;;;AACAC,EAAAA,OAAO,CAACC,IAAR,CAAc;AAChB;AACA,WAAWF,YAAa;AACxB,GAHE;AAKAF,EAAAA,MAAM,CAACE,YAAD,CAAN,GAAuB,IAAvB;AACD;;AAEM,SAASG,yBAAT,CACLH,YADK,EAELI,OAFK,EAGL;AACA,QAAM,IAAI1B,KAAJ,CACH,IAAGsB,YAAa,wGAAuGI,OAAQ,EAD5H,CAAN;AAGD;;AAEM,SAASC,yBAAT,CACLL,YADK,EAELM,eAFK,EAGL;AACA,QAAM,IAAI7B,cAAJ,CACH,QAAOuB,YAAa,mCAAkCM,eAAgB,oCADnE,EAEJD,yBAFI,CAAN;AAID","sourcesContent":["import prettyFormat from 'pretty-format';\n\nexport class ErrorWithStack extends Error {\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport const createLibraryNotSupportedError = (error: unknown): Error =>\n new Error(\n `Currently the only supported library to search by text is \"react-native\".\\n\\n${\n error instanceof Error ? error.message : ''\n }`\n );\n\nexport const prepareErrorMessage = (\n // TS states that error caught in a catch close are of type `unknown`\n // most real cases will be `Error`, but better safe than sorry\n error: unknown,\n name?: string,\n value?: unknown\n): string => {\n let errorMessage: string;\n if (error instanceof Error) {\n // Strip info about custom predicate\n errorMessage = error.message.replace(\n / matching custom predicate[^]*/gm,\n ''\n );\n } else if (error && typeof error === 'object') {\n errorMessage = error.toString();\n } else {\n errorMessage = 'Caught unknown error';\n }\n\n if (name && value) {\n errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;\n }\n return errorMessage;\n};\n\nexport const createQueryByError = (\n error: NonNullable<unknown>,\n callsite: Function\n): null => {\n if (error instanceof Error) {\n if (error.message.includes('No instances found')) {\n return null;\n }\n throw new ErrorWithStack(error.message, callsite);\n }\n\n throw new ErrorWithStack(\n // generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that\n // Converting as any with extra safe optional chaining will do the job just as well\n `Query: caught unknown error type: ${typeof error}, value: ${(error as any)?.toString?.()}`,\n callsite\n );\n};\n\nexport function copyStackTrace(target: unknown, stackTraceSource: Error) {\n if (target instanceof Error && stackTraceSource.stack) {\n target.stack = stackTraceSource.stack.replace(\n stackTraceSource.message,\n target.message\n );\n }\n}\n\nconst warned: { [functionName: string]: boolean } = {};\n\nexport function printDeprecationWarning(functionName: string) {\n if (warned[functionName]) {\n return;\n }\n\n // eslint-disable-next-line no-console\n console.warn(`\n Deprecation Warning:\n Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.\n `);\n\n warned[functionName] = true;\n}\n\nexport function throwRemovedFunctionError(\n functionName: string,\n docsRef: string\n) {\n throw new Error(\n `\"${functionName}\" has been removed.\\n\\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`\n );\n}\n\nexport function throwRenamedFunctionError(\n functionName: string,\n newFunctionName: string\n) {\n throw new ErrorWithStack(\n `The \"${functionName}\" function has been renamed to \"${newFunctionName}\". Please replace all occurrences.`,\n throwRenamedFunctionError\n );\n}\n"],"file":"errors.js"}
@@ -0,0 +1,3 @@
1
+ import type { ReactTestInstance } from 'react-test-renderer';
2
+ import * as React from 'react';
3
+ export declare const filterNodeByType: (node: ReactTestInstance | React.ReactElement, type: React.ElementType) => boolean;
@@ -7,4 +7,5 @@ exports.filterNodeByType = void 0;
7
7
 
8
8
  const filterNodeByType = (node, type) => node.type === type;
9
9
 
10
- exports.filterNodeByType = filterNodeByType;
10
+ exports.filterNodeByType = filterNodeByType;
11
+ //# sourceMappingURL=filterNodeByType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/filterNodeByType.ts"],"names":["filterNodeByType","node","type"],"mappings":";;;;;;;AAGO,MAAMA,gBAAgB,GAAG,CAC9BC,IAD8B,EAE9BC,IAF8B,KAG3BD,IAAI,CAACC,IAAL,KAAcA,IAHZ","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport * as React from 'react';\n\nexport const filterNodeByType = (\n node: ReactTestInstance | React.ReactElement,\n type: React.ElementType\n) => node.type === type;\n"],"file":"filterNodeByType.js"}
@@ -0,0 +1,3 @@
1
+ import type { ReactTestRendererJSON } from 'react-test-renderer';
2
+ declare const format: (input: ReactTestRendererJSON | ReactTestRendererJSON[]) => string;
3
+ export default format;
@@ -7,9 +7,9 @@ exports.default = void 0;
7
7
 
8
8
  var _prettyFormat = _interopRequireWildcard(require("pretty-format"));
9
9
 
10
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
11
 
12
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
12
+ 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; }
13
13
 
14
14
  const format = input => (0, _prettyFormat.default)(input, {
15
15
  plugins: [_prettyFormat.plugins.ReactTestComponent, _prettyFormat.plugins.ReactElement],
@@ -17,4 +17,5 @@ const format = input => (0, _prettyFormat.default)(input, {
17
17
  });
18
18
 
19
19
  var _default = format;
20
- exports.default = _default;
20
+ exports.default = _default;
21
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/format.ts"],"names":["format","input","plugins","ReactTestComponent","ReactElement","highlight"],"mappings":";;;;;;;AACA;;;;;;AAEA,MAAMA,MAAM,GAAIC,KAAD,IACb,2BAAaA,KAAb,EAAoB;AAClBC,EAAAA,OAAO,EAAE,CAACA,sBAAQC,kBAAT,EAA6BD,sBAAQE,YAArC,CADS;AAElBC,EAAAA,SAAS,EAAE;AAFO,CAApB,CADF;;eAMeL,M","sourcesContent":["import type { ReactTestRendererJSON } from 'react-test-renderer';\nimport prettyFormat, { plugins } from 'pretty-format';\n\nconst format = (input: ReactTestRendererJSON | ReactTestRendererJSON[]) =>\n prettyFormat(input, {\n plugins: [plugins.ReactTestComponent, plugins.ReactElement],\n highlight: true,\n });\n\nexport default format;\n"],"file":"format.js"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="react-native" />
2
+ /// <reference types="node" />
3
+ declare function runWithRealTimers<T>(callback: () => T): T;
4
+ declare const jestFakeTimersAreEnabled: () => boolean;
5
+ declare const clearTimeoutFn: typeof clearTimeout, setImmediateFn: typeof setImmediate, setTimeoutFn: typeof setTimeout;
6
+ export { runWithRealTimers, jestFakeTimersAreEnabled, clearTimeoutFn as clearTimeout, setImmediateFn as setImmediate, setTimeoutFn as setTimeout, };
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.jestFakeTimersAreEnabled = exports.clearTimeout = void 0;
6
7
  exports.runWithRealTimers = runWithRealTimers;
7
- exports.setTimeout = exports.setImmediate = exports.clearTimeout = exports.jestFakeTimersAreEnabled = void 0;
8
+ exports.setTimeout = exports.setImmediate = void 0;
8
9
  // Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
9
10
 
10
11
  /* globals jest */
@@ -32,15 +33,16 @@ function getJestFakeTimersType() {
32
33
  return null;
33
34
  }
34
35
 
35
- if (typeof globalObj.setTimeout._isMockFunction !== 'undefined' && globalObj.setTimeout._isMockFunction) {
36
+ if ( // @ts-expect-error jest mutates setTimeout
37
+ typeof globalObj.setTimeout._isMockFunction !== 'undefined' && // @ts-expect-error jest mutates setTimeout
38
+ globalObj.setTimeout._isMockFunction) {
36
39
  return 'legacy';
37
40
  }
38
41
 
39
- if (typeof globalObj.setTimeout.clock !== 'undefined' && // $FlowIgnore[prop-missing]
40
- typeof jest.getRealSystemTime !== 'undefined') {
42
+ if ( // @ts-expect-error jest mutates setTimeout
43
+ typeof globalObj.setTimeout.clock !== 'undefined' && typeof jest.getRealSystemTime !== 'undefined') {
41
44
  try {
42
45
  // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
43
- // $FlowExpectedError
44
46
  jest.getRealSystemTime();
45
47
  return 'modern';
46
48
  } catch {// not using Jest's modern fake timers
@@ -74,4 +76,5 @@ const {
74
76
  } = runWithRealTimers(bindTimeFunctions);
75
77
  exports.setTimeout = setTimeoutFn;
76
78
  exports.setImmediate = setImmediateFn;
77
- exports.clearTimeout = clearTimeoutFn;
79
+ exports.clearTimeout = clearTimeoutFn;
80
+ //# sourceMappingURL=timers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/timers.ts"],"names":["globalObj","window","global","runWithRealTimers","callback","fakeTimersType","getJestFakeTimersType","jest","useRealTimers","callbackReturnValue","useFakeTimers","setTimeout","_isMockFunction","clock","getRealSystemTime","jestFakeTimersAreEnabled","Boolean","setImmediatePolyfill","fn","bindTimeFunctions","clearTimeoutFn","clearTimeout","setImmediateFn","setImmediate","setTimeoutFn"],"mappings":";;;;;;;;AAAA;;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAA3D,C,CAEA;;AACA,SAASE,iBAAT,CAA8BC,QAA9B,EAAoD;AAClD,QAAMC,cAAc,GAAGC,qBAAqB,EAA5C;;AACA,MAAID,cAAJ,EAAoB;AAClBE,IAAAA,IAAI,CAACC,aAAL;AACD;;AAED,QAAMC,mBAAmB,GAAGL,QAAQ,EAApC;;AAEA,MAAIC,cAAJ,EAAoB;AAClBE,IAAAA,IAAI,CAACG,aAAL,CAAmBL,cAAnB;AACD;;AAED,SAAOI,mBAAP;AACD;;AAED,SAASH,qBAAT,GAAiC;AAC/B;AACA,MACE,OAAOC,IAAP,KAAgB,WAAhB,IACA,OAAOP,SAAS,CAACW,UAAjB,KAAgC,WAFlC,EAGE;AACA,WAAO,IAAP;AACD;;AAED,OACE;AACA,SAAOX,SAAS,CAACW,UAAV,CAAqBC,eAA5B,KAAgD,WAAhD,IACA;AACAZ,EAAAA,SAAS,CAACW,UAAV,CAAqBC,eAJvB,EAKE;AACA,WAAO,QAAP;AACD;;AAED,OACE;AACA,SAAOZ,SAAS,CAACW,UAAV,CAAqBE,KAA5B,KAAsC,WAAtC,IACA,OAAON,IAAI,CAACO,iBAAZ,KAAkC,WAHpC,EAIE;AACA,QAAI;AACF;AACAP,MAAAA,IAAI,CAACO,iBAAL;AACA,aAAO,QAAP;AACD,KAJD,CAIE,MAAM,CACN;AACD;AACF;;AACD,SAAO,IAAP;AACD;;AAED,MAAMC,wBAAwB,GAAG,MAC/BC,OAAO,CAACV,qBAAqB,EAAtB,CADT,C,CAGA;;;;;AACA,SAASW,oBAAT,CAA8BC,EAA9B,EAA4C;AAC1C,SAAOlB,SAAS,CAACW,UAAV,CAAqBO,EAArB,EAAyB,CAAzB,CAAP;AACD;;AAQD,SAASC,iBAAT,GAAgD;AAC9C,SAAO;AACLC,IAAAA,cAAc,EAAEpB,SAAS,CAACqB,YADrB;AAELC,IAAAA,cAAc,EAAEtB,SAAS,CAACuB,YAAV,IAA0BN,oBAFrC;AAGLO,IAAAA,YAAY,EAAExB,SAAS,CAACW;AAHnB,GAAP;AAKD;;AAED,MAAM;AAAES,EAAAA,cAAF;AAAkBE,EAAAA,cAAlB;AAAkCE,EAAAA;AAAlC,IAAmDrB,iBAAiB,CACxEgB,iBADwE,CAA1E","sourcesContent":["// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js\n/* globals jest */\nconst globalObj = typeof window === 'undefined' ? global : window;\n\n// Currently this fn only supports jest timers, but it could support other test runners in the future.\nfunction runWithRealTimers<T>(callback: () => T): T {\n const fakeTimersType = getJestFakeTimersType();\n if (fakeTimersType) {\n jest.useRealTimers();\n }\n\n const callbackReturnValue = callback();\n\n if (fakeTimersType) {\n jest.useFakeTimers(fakeTimersType);\n }\n\n return callbackReturnValue;\n}\n\nfunction getJestFakeTimersType() {\n // istanbul ignore if\n if (\n typeof jest === 'undefined' ||\n typeof globalObj.setTimeout === 'undefined'\n ) {\n return null;\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&\n // @ts-expect-error jest mutates setTimeout\n globalObj.setTimeout._isMockFunction\n ) {\n return 'legacy';\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout.clock !== 'undefined' &&\n typeof jest.getRealSystemTime !== 'undefined'\n ) {\n try {\n // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws\n jest.getRealSystemTime();\n return 'modern';\n } catch {\n // not using Jest's modern fake timers\n }\n }\n return null;\n}\n\nconst jestFakeTimersAreEnabled = (): boolean =>\n Boolean(getJestFakeTimersType());\n\n// we only run our tests in node, and setImmediate is supported in node.\nfunction setImmediatePolyfill(fn: Function) {\n return globalObj.setTimeout(fn, 0);\n}\n\ntype BindTimeFunctions = {\n clearTimeoutFn: typeof clearTimeout;\n setImmediateFn: typeof setImmediate;\n setTimeoutFn: typeof setTimeout;\n};\n\nfunction bindTimeFunctions(): BindTimeFunctions {\n return {\n clearTimeoutFn: globalObj.clearTimeout,\n setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,\n setTimeoutFn: globalObj.setTimeout,\n };\n}\n\nconst { clearTimeoutFn, setImmediateFn, setTimeoutFn } = runWithRealTimers(\n bindTimeFunctions\n) as BindTimeFunctions;\n\nexport {\n runWithRealTimers,\n jestFakeTimersAreEnabled,\n clearTimeoutFn as clearTimeout,\n setImmediateFn as setImmediate,\n setTimeoutFn as setTimeout,\n};\n"],"file":"timers.js"}
@@ -0,0 +1 @@
1
+ export * from './pure';