@testing-library/react-native 13.2.1 → 13.3.0-beta.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 (42) hide show
  1. package/build/fire-event.d.ts +7 -0
  2. package/build/fire-event.js +24 -4
  3. package/build/fire-event.js.map +1 -1
  4. package/build/helpers/accessibility.js +3 -0
  5. package/build/helpers/accessibility.js.map +1 -1
  6. package/build/pure.d.ts +3 -1
  7. package/build/pure.js +15 -1
  8. package/build/pure.js.map +1 -1
  9. package/build/render-act.d.ts +1 -0
  10. package/build/render-act.js +13 -0
  11. package/build/render-act.js.map +1 -1
  12. package/build/render-async.d.ts +104 -0
  13. package/build/render-async.js +104 -0
  14. package/build/render-async.js.map +1 -0
  15. package/build/render.d.ts +8 -2
  16. package/build/render.js +24 -11
  17. package/build/render.js.map +1 -1
  18. package/build/screen.js +4 -1
  19. package/build/screen.js.map +1 -1
  20. package/build/test-utils/console.d.ts +1 -0
  21. package/build/test-utils/console.js +17 -0
  22. package/build/test-utils/console.js.map +1 -0
  23. package/build/tsconfig.release.tsbuildinfo +1 -1
  24. package/build/user-event/clear.js +4 -4
  25. package/build/user-event/clear.js.map +1 -1
  26. package/build/user-event/paste.js +8 -8
  27. package/build/user-event/paste.js.map +1 -1
  28. package/build/user-event/press/press.js +6 -6
  29. package/build/user-event/press/press.js.map +1 -1
  30. package/build/user-event/scroll/scroll-to.js +7 -7
  31. package/build/user-event/scroll/scroll-to.js.map +1 -1
  32. package/build/user-event/type/type.js +11 -11
  33. package/build/user-event/type/type.js.map +1 -1
  34. package/build/user-event/utils/dispatch-event.d.ts +1 -1
  35. package/build/user-event/utils/dispatch-event.js +3 -3
  36. package/build/user-event/utils/dispatch-event.js.map +1 -1
  37. package/build/wait-for.js +3 -1
  38. package/build/wait-for.js.map +1 -1
  39. package/package.json +3 -3
  40. package/build/test-utils/index.d.ts +0 -1
  41. package/build/test-utils/index.js +0 -17
  42. package/build/test-utils/index.js.map +0 -1
@@ -24,12 +24,12 @@ async function type(element, text, options) {
24
24
  }
25
25
  const keys = (0, _parseKeys.parseKeys)(text);
26
26
  if (!options?.skipPress) {
27
- (0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
27
+ await (0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
28
28
  }
29
- (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
29
+ await (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
30
30
  if (!options?.skipPress) {
31
31
  await (0, _utils.wait)(this.config);
32
- (0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
32
+ await (0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
33
33
  }
34
34
  let currentText = (0, _textInput.getTextInputValue)(element);
35
35
  for (const key of keys) {
@@ -47,11 +47,11 @@ async function type(element, text, options) {
47
47
  const finalText = (0, _textInput.getTextInputValue)(element);
48
48
  await (0, _utils.wait)(this.config);
49
49
  if (options?.submitEditing) {
50
- (0, _utils.dispatchEvent)(element, 'submitEditing', _eventBuilder.EventBuilder.TextInput.submitEditing(finalText));
50
+ await (0, _utils.dispatchEvent)(element, 'submitEditing', _eventBuilder.EventBuilder.TextInput.submitEditing(finalText));
51
51
  }
52
52
  if (!options?.skipBlur) {
53
- (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(finalText));
54
- (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
53
+ await (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(finalText));
54
+ await (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
55
55
  }
56
56
  }
57
57
  async function emitTypingEvents(element, {
@@ -62,7 +62,7 @@ async function emitTypingEvents(element, {
62
62
  }) {
63
63
  const isMultiline = element.props.multiline === true;
64
64
  await (0, _utils.wait)(config);
65
- (0, _utils.dispatchEvent)(element, 'keyPress', _eventBuilder.EventBuilder.TextInput.keyPress(key));
65
+ await (0, _utils.dispatchEvent)(element, 'keyPress', _eventBuilder.EventBuilder.TextInput.keyPress(key));
66
66
 
67
67
  // Platform difference (based on experiments):
68
68
  // - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached
@@ -71,19 +71,19 @@ async function emitTypingEvents(element, {
71
71
  return;
72
72
  }
73
73
  _nativeState.nativeState.valueForElement.set(element, text);
74
- (0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
75
- (0, _utils.dispatchEvent)(element, 'changeText', text);
74
+ await (0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
75
+ await (0, _utils.dispatchEvent)(element, 'changeText', text);
76
76
  const selectionRange = {
77
77
  start: text.length,
78
78
  end: text.length
79
79
  };
80
- (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
80
+ await (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
81
81
 
82
82
  // According to the docs only multiline TextInput emits contentSizeChange event
83
83
  // @see: https://reactnative.dev/docs/textinput#oncontentsizechange
84
84
  if (isMultiline) {
85
85
  const contentSize = (0, _utils.getTextContentSize)(text);
86
- (0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
86
+ await (0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
87
87
  }
88
88
  }
89
89
  function applyKey(text, key) {
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","_parseKeys","type","element","text","options","isHostTextInput","ErrorWithStack","isEditableTextInput","isPointerEventEnabled","keys","parseKeys","skipPress","dispatchEvent","EventBuilder","Common","touch","focus","wait","config","currentText","getTextInputValue","key","previousText","proposedText","applyKey","isAccepted","isTextChangeAccepted","emitTypingEvents","finalText","submitEditing","TextInput","skipBlur","endEditing","blur","isMultiline","props","multiline","keyPress","nativeState","valueForElement","set","change","selectionRange","start","length","end","selectionChange","contentSize","getTextContentSize","contentSizeChange","slice","maxLength","undefined"],"sources":["../../../src/user-event/type/type.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, getTextContentSize, wait } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n skipBlur?: boolean;\n}\n\nexport async function type(\n this: UserEventInstance,\n element: ReactTestInstance,\n text: string,\n options?: TypeOptions,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `type() works only with host \"TextInput\" elements. Passed element has type \"${element.type}\".`,\n type,\n );\n }\n\n // Skip events if the element is disabled\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n const keys = parseKeys(text);\n\n if (!options?.skipPress) {\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n if (!options?.skipPress) {\n await wait(this.config);\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n }\n\n let currentText = getTextInputValue(element);\n for (const key of keys) {\n const previousText = getTextInputValue(element);\n const proposedText = applyKey(previousText, key);\n const isAccepted = isTextChangeAccepted(element, proposedText);\n currentText = isAccepted ? proposedText : previousText;\n\n await emitTypingEvents(element, {\n config: this.config,\n key,\n text: currentText,\n isAccepted,\n });\n }\n\n const finalText = getTextInputValue(element);\n await wait(this.config);\n\n if (options?.submitEditing) {\n dispatchEvent(element, 'submitEditing', EventBuilder.TextInput.submitEditing(finalText));\n }\n\n if (!options?.skipBlur) {\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n }\n}\n\ntype EmitTypingEventsContext = {\n config: UserEventConfig;\n key: string;\n text: string;\n isAccepted?: boolean;\n};\n\nexport async function emitTypingEvents(\n element: ReactTestInstance,\n { config, key, text, isAccepted }: EmitTypingEventsContext,\n) {\n const isMultiline = element.props.multiline === true;\n\n await wait(config);\n dispatchEvent(element, 'keyPress', EventBuilder.TextInput.keyPress(key));\n\n // Platform difference (based on experiments):\n // - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached\n // - Android: TextInputs does not emit any events\n if (isAccepted === false) {\n return;\n }\n\n nativeState.valueForElement.set(element, text);\n dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n dispatchEvent(element, 'changeText', text);\n\n const selectionRange = {\n start: text.length,\n end: text.length,\n };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n}\n\nfunction applyKey(text: string, key: string) {\n if (key === 'Enter') {\n return `${text}\\n`;\n }\n\n if (key === 'Backspace') {\n return text.slice(0, -1);\n }\n\n return text + key;\n}\n\nfunction isTextChangeAccepted(element: ReactTestInstance, text: string) {\n const maxLength = element.props.maxLength;\n return maxLength === undefined || text.length <= maxLength;\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,OAAA,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I,CAACyC,MAAM,IAAIO,SAAS;AAC5D","ignoreList":[]}
1
+ {"version":3,"file":"type.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","_parseKeys","type","element","text","options","isHostTextInput","ErrorWithStack","isEditableTextInput","isPointerEventEnabled","keys","parseKeys","skipPress","dispatchEvent","EventBuilder","Common","touch","focus","wait","config","currentText","getTextInputValue","key","previousText","proposedText","applyKey","isAccepted","isTextChangeAccepted","emitTypingEvents","finalText","submitEditing","TextInput","skipBlur","endEditing","blur","isMultiline","props","multiline","keyPress","nativeState","valueForElement","set","change","selectionRange","start","length","end","selectionChange","contentSize","getTextContentSize","contentSizeChange","slice","maxLength","undefined"],"sources":["../../../src/user-event/type/type.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, getTextContentSize, wait } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n skipBlur?: boolean;\n}\n\nexport async function type(\n this: UserEventInstance,\n element: ReactTestInstance,\n text: string,\n options?: TypeOptions,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `type() works only with host \"TextInput\" elements. Passed element has type \"${element.type}\".`,\n type,\n );\n }\n\n // Skip events if the element is disabled\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n const keys = parseKeys(text);\n\n if (!options?.skipPress) {\n await dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n }\n\n await dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n if (!options?.skipPress) {\n await wait(this.config);\n await dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n }\n\n let currentText = getTextInputValue(element);\n for (const key of keys) {\n const previousText = getTextInputValue(element);\n const proposedText = applyKey(previousText, key);\n const isAccepted = isTextChangeAccepted(element, proposedText);\n currentText = isAccepted ? proposedText : previousText;\n\n await emitTypingEvents(element, {\n config: this.config,\n key,\n text: currentText,\n isAccepted,\n });\n }\n\n const finalText = getTextInputValue(element);\n await wait(this.config);\n\n if (options?.submitEditing) {\n await dispatchEvent(element, 'submitEditing', EventBuilder.TextInput.submitEditing(finalText));\n }\n\n if (!options?.skipBlur) {\n await dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n await dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n }\n}\n\ntype EmitTypingEventsContext = {\n config: UserEventConfig;\n key: string;\n text: string;\n isAccepted?: boolean;\n};\n\nexport async function emitTypingEvents(\n element: ReactTestInstance,\n { config, key, text, isAccepted }: EmitTypingEventsContext,\n) {\n const isMultiline = element.props.multiline === true;\n\n await wait(config);\n await dispatchEvent(element, 'keyPress', EventBuilder.TextInput.keyPress(key));\n\n // Platform difference (based on experiments):\n // - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached\n // - Android: TextInputs does not emit any events\n if (isAccepted === false) {\n return;\n }\n\n nativeState.valueForElement.set(element, text);\n await dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n await dispatchEvent(element, 'changeText', text);\n\n const selectionRange = {\n start: text.length,\n end: text.length,\n };\n await dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(selectionRange),\n );\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n await dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n}\n\nfunction applyKey(text: string, key: string) {\n if (key === 'Enter') {\n return `${text}\\n`;\n }\n\n if (key === 'Backspace') {\n return text.slice(0, -1);\n }\n\n return text + key;\n}\n\nfunction isTextChangeAccepted(element: ReactTestInstance, text: string) {\n const maxLength = element.props.maxLength;\n return maxLength === undefined || text.length <= maxLength;\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAQO,eAAeQ,IAAIA,CAExBC,OAA0B,EAC1BC,IAAY,EACZC,OAAqB,EACN;EACf,IAAI,CAAC,IAAAC,mCAAe,EAACH,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAII,sBAAc,CACtB,8EAA8EJ,OAAO,CAACD,IAAI,IAAI,EAC9FA,IACF,CAAC;EACH;;EAEA;EACA,IAAI,CAAC,IAAAM,8BAAmB,EAACL,OAAO,CAAC,IAAI,CAAC,IAAAM,oCAAqB,EAACN,OAAO,CAAC,EAAE;IACpE;EACF;EAEA,MAAMO,IAAI,GAAG,IAAAC,oBAAS,EAACP,IAAI,CAAC;EAE5B,IAAI,CAACC,OAAO,EAAEO,SAAS,EAAE;IACvB,MAAM,IAAAC,oBAAa,EAACV,OAAO,EAAE,SAAS,EAAEW,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;EACtE;EAEA,MAAM,IAAAH,oBAAa,EAACV,OAAO,EAAE,OAAO,EAAEW,0BAAY,CAACC,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC;EAElE,IAAI,CAACZ,OAAO,EAAEO,SAAS,EAAE;IACvB,MAAM,IAAAM,WAAI,EAAC,IAAI,CAACC,MAAM,CAAC;IACvB,MAAM,IAAAN,oBAAa,EAACV,OAAO,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AI,CAAC+C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC1B;EAEA,OAAO/C,IAAI,GAAGkB,GAAG;AACnB;AAEA,SAASK,oBAAoBA,CAACxB,OAA0B,EAAEC,IAAY,EAAE;EACtE,MAAMgD,SAAS,GAAGjD,OAAO,CAACiC,KAAK,CAACgB,SAAS;EACzC,OAAOA,SAAS,KAAKC,SAAS,IAAIjD,IAAI,CAACyC,MAAM,IAAIO,SAAS;AAC5D","ignoreList":[]}
@@ -6,4 +6,4 @@ import type { ReactTestInstance } from 'react-test-renderer';
6
6
  * @param eventName name of the event
7
7
  * @param event event payload(s)
8
8
  */
9
- export declare function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]): void;
9
+ export declare function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]): Promise<void>;
@@ -15,7 +15,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
15
15
  * @param eventName name of the event
16
16
  * @param event event payload(s)
17
17
  */
18
- function dispatchEvent(element, eventName, ...event) {
18
+ async function dispatchEvent(element, eventName, ...event) {
19
19
  if (!(0, _componentTree.isElementMounted)(element)) {
20
20
  return;
21
21
  }
@@ -24,8 +24,8 @@ function dispatchEvent(element, eventName, ...event) {
24
24
  return;
25
25
  }
26
26
 
27
- // This will be called synchronously.
28
- void (0, _act.default)(() => {
27
+ // eslint-disable-next-line require-await
28
+ await (0, _act.default)(async () => {
29
29
  handler(...event);
30
30
  });
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\n\nimport act from '../../act';\nimport { getEventHandler } from '../../event-handler';\nimport { isElementMounted } from '../../helpers/component-tree';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAAgE,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,OAA0B,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAChG,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAG,IAAAC,6BAAe,EAACL,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\n\nimport act from '../../act';\nimport { getEventHandler } from '../../event-handler';\nimport { isElementMounted } from '../../helpers/component-tree';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport async function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n ...event: unknown[]\n) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // eslint-disable-next-line require-await\n await act(async () => {\n handler(...event);\n });\n}\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAAgE,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeG,aAAaA,CACjCC,OAA0B,EAC1BC,SAAiB,EACjB,GAAGC,KAAgB,EACnB;EACA,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAG,IAAAC,6BAAe,EAACL,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,MAAM,IAAAE,YAAG,EAAC,YAAY;IACpBF,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ","ignoreList":[]}
package/build/wait-for.js CHANGED
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = waitFor;
7
+ var _act = _interopRequireDefault(require("./act"));
7
8
  var _config = require("./config");
8
9
  var _flushMicroTasks = require("./flush-micro-tasks");
9
10
  var _errors = require("./helpers/errors");
10
11
  var _timers = require("./helpers/timers");
11
12
  var _wrapAsync = require("./helpers/wrap-async");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
14
  /* globals jest */
13
15
 
14
16
  const DEFAULT_INTERVAL = 50;
@@ -59,7 +61,7 @@ function waitForInternal(expectation, {
59
61
  // third party code that's setting up recursive timers so rapidly that
60
62
  // the user's timer's don't get a chance to resolve. So we'll advance
61
63
  // by an interval instead. (We have a test for this case).
62
- jest.advanceTimersByTime(interval);
64
+ await (0, _act.default)(async () => await jest.advanceTimersByTime(interval));
63
65
 
64
66
  // It's really important that checkExpectation is run *before* we flush
65
67
  // in-flight promises. To be honest, I'm not sure why, and I can't quite
@@ -1 +1 @@
1
- {"version":3,"file":"wait-for.js","names":["_config","require","_flushMicroTasks","_errors","_timers","_wrapAsync","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","handleTimeout","jest","advanceTimersByTime","flushMicroTasks","setTimeout","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","String","waitFor","options","ErrorWithStack","optionsWithStackTrace","wrapAsync"],"sources":["../src/wait-for.ts"],"sourcesContent":["/* globals jest */\nimport { getConfig } from './config';\nimport { flushMicroTasks } from './flush-micro-tasks';\nimport { copyStackTrace, ErrorWithStack } from './helpers/errors';\nimport { clearTimeout, jestFakeTimersAreEnabled, setTimeout } from './helpers/timers';\nimport { wrapAsync } from './helpers/wrap-async';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: Error) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions,\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n let overallTimeoutTimer: NodeJS.Timeout | null = null;\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n handleTimeout();\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(done: { type: 'result'; result: T } | { type: 'error'; error: unknown }) {\n finished = true;\n if (overallTimeoutTimer) {\n clearTimeout(overallTimeoutTimer);\n }\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-expect-error result can be a promise\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as unknown as Promise<T>;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n },\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error: Error;\n if (lastError) {\n if (lastError instanceof Error) {\n error = lastError;\n } else {\n error = new Error(String(lastError));\n }\n\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n const result = onTimeout(error);\n if (result) {\n error = result;\n }\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default function waitFor<T>(expectation: () => T, options?: WaitForOptions): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n return wrapAsync(() => wa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F;MACAL,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAO;QAAEd;MAAM,CAAC,CAAC;IAClC;EACF,CAAC,CAAC;AACJ;AAEe,SAASqB,OAAOA,CAAIzC,WAAoB,EAAE0C,OAAwB,EAAc;EAC7F;EACA,MAAMrC,eAAe,GAAG,IAAIsC,sBAAc,CAAC,mBAAmB,EAAEF,OAAO,CAAC;EACxE,MAAMG,qBAAqB,GAAG;IAAEvC,eAAe;IAAE,GAAGqC;EAAQ,CAAC;EAE7D,OAAO,IAAAG,oBAAS,EAAC,MAAM9C,eAAe,CAACC,WAAW,EAAE4C,qBAAqB,CAAC,CAAC;AAC7E","ignoreList":[]}
1
+ {"version":3,"file":"wait-for.js","names":["_act","_interopRequireDefault","require","_config","_flushMicroTasks","_errors","_timers","_wrapAsync","e","__esModule","default","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","handleTimeout","act","jest","advanceTimersByTime","flushMicroTasks","setTimeout","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","String","waitFor","options","ErrorWithStack","optionsWithStackTrace","wrapAsync"],"sources":["../src/wait-for.ts"],"sourcesContent":["/* globals jest */\nimport act from './act';\nimport { getConfig } from './config';\nimport { flushMicroTasks } from './flush-micro-tasks';\nimport { copyStackTrace, ErrorWithStack } from './helpers/errors';\nimport { clearTimeout, jestFakeTimersAreEnabled, setTimeout } from './helpers/timers';\nimport { wrapAsync } from './helpers/wrap-async';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: Error) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions,\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n let overallTimeoutTimer: NodeJS.Timeout | null = null;\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n handleTimeout();\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n await act(async () => await jest.advanceTimersByTime(interval));\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(done: { type: 'result'; result: T } | { type: 'error'; error: unknown }) {\n finished = true;\n if (overallTimeoutTimer) {\n clearTimeout(overallTimeoutTimer);\n }\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-expect-error result can be a promise\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as unknown as Promise<T>;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n },\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error: Error;\n if (lastError) {\n if (lastError instanceof Error) {\n error = lastError;\n } else {\n error = new Error(String(lastError));\n }\n\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n const result = onTimeout(error);\n if (result) {\n error = result;\n }\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default function waitFor<T>(expectation: () => T, options?: WaitForOptions): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n return wrapAsync(() => waitForInternal(expectation, optionsWithStackTrace));\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAAiD,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AANjD;;AAQA,MAAMG,gBAAgB,GAAG,EAAE;AAS3B,SAASC,eAAeA,CACtBC,WAAoB,EACpB;EACEC,OAAO,GAAG,IAAAC,iBAAS,EAAC,CAAC,CAACC,gBAAgB;EACtCC,QAAQ,GAAGN,gBAAgB;EAC3BO,eAAe;EACfC;AACc,CAAC,EACL;EACZ,IAAI,OAAON,WAAW,KAAK,UAAU,EAAE;IACrC,MAAM,IAAIO,SAAS,CAAC,+CAA+C,CAAC;EACtE;;EAEA;EACA,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;IAC5C,IAAIC,SAAkB,EAAEC,UAAyC;IACjE,IAAIC,QAAQ,GAAG,KAAK;IACpB,IAAIC,aAAa,GAAG,MAAM;IAE1B,IAAIC,mBAA0C,GAAG,IAAI;IAErD,MAAMC,eAAe,GAAG,IAAAC,gCAAwB,EAAC,CAAC;IAElD,IAAID,eAAe,EAAE;MACnBE,gBAAgB,CAAC,CAAC;MAClB;MACA;MACA;M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K,CAACoB,MAAM,CAAC9B,SAAS,CAAC,CAAC;QACtC;QAEA,IAAIN,eAAe,EAAE;UACnB,IAAAiB,sBAAc,EAACF,KAAK,EAAEf,eAAe,CAAC;QACxC;MACF,CAAC,MAAM;QACLe,KAAK,GAAG,IAAIC,KAAK,CAAC,uBAAuB,CAAC;QAC1C,IAAIhB,eAAe,EAAE;UACnB,IAAAiB,sBAAc,EAACF,KAAK,EAAEf,eAAe,CAAC;QACxC;MACF;MACA,IAAI,OAAOC,SAAS,KAAK,UAAU,EAAE;QACnC,MAAM8B,MAAM,GAAG9B,SAAS,CAACc,KAAK,CAAC;QAC/B,IAAIgB,MAAM,EAAE;UACVhB,KAAK,GAAGgB,MAAM;QAChB;MACF;MACAL,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAO;QAAEf;MAAM,CAAC,CAAC;IAClC;EACF,CAAC,CAAC;AACJ;AAEe,SAASsB,OAAOA,CAAI1C,WAAoB,EAAE2C,OAAwB,EAAc;EAC7F;EACA,MAAMtC,eAAe,GAAG,IAAIuC,sBAAc,CAAC,mBAAmB,EAAEF,OAAO,CAAC;EACxE,MAAMG,qBAAqB,GAAG;IAAExC,eAAe;IAAE,GAAGsC;EAAQ,CAAC;EAE7D,OAAO,IAAAG,oBAAS,EAAC,MAAM/C,eAAe,CAACC,WAAW,EAAE6C,qBAAqB,CAAC,CAAC;AAC7E","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/react-native",
3
- "version": "13.2.1",
3
+ "version": "13.3.0-beta.0",
4
4
  "description": "Simple and complete React Native testing utilities that encourage good testing practices.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -72,7 +72,7 @@
72
72
  "@babel/preset-react": "^7.25.9",
73
73
  "@babel/preset-typescript": "^7.26.0",
74
74
  "@callstack/eslint-config": "^15.0.0",
75
- "@react-native/babel-preset": "0.80.1",
75
+ "@react-native/babel-preset": "0.81.0-rc.3",
76
76
  "@release-it/conventional-changelog": "^10.0.0",
77
77
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
78
78
  "@types/jest": "^30.0.0",
@@ -88,7 +88,7 @@
88
88
  "jest": "^30.0.2",
89
89
  "prettier": "^2.8.8",
90
90
  "react": "19.1.0",
91
- "react-native": "0.80.1",
91
+ "react-native": "0.81.0-rc.3",
92
92
  "react-native-gesture-handler": "^2.27.1",
93
93
  "react-test-renderer": "19.1.0",
94
94
  "release-it": "^19.0.3",
@@ -1 +0,0 @@
1
- export * from './events';
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _events = require("./events");
7
- Object.keys(_events).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _events[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _events[key];
14
- }
15
- });
16
- });
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_events","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../src/test-utils/index.ts"],"sourcesContent":["export * from './events';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}