@testing-library/react-native 12.3.2 → 12.3.3

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.
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  ## The problem
22
22
 
23
- You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
23
+ You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
24
24
 
25
25
  ## This solution
26
26
 
@@ -50,7 +50,7 @@ This library has a `peerDependencies` listing for `react-test-renderer`. Make su
50
50
 
51
51
  ### Additional Jest matchers
52
52
 
53
- In order to use additional React Native-specific jest matchers from [@testing-library/jest-native](https://github.com/testing-library/jest-native) package add it to your project:
53
+ To use additional React Native-specific jest matchers from [@testing-library/jest-native](https://github.com/testing-library/jest-native) package add it to your project:
54
54
 
55
55
  #### Using `yarn`
56
56
 
@@ -64,7 +64,7 @@ yarn add --dev @testing-library/jest-native
64
64
  npm install --save-dev @testing-library/jest-native
65
65
  ```
66
66
 
67
- Then automatically add it to your jest tests by using `setupFilesAfterEnv` option in your Jest configuration (it's usually located either in `package.json` under `"jest"` key or in a `jest.config.json` file):
67
+ Then automatically add it to your jest tests by using the `setupFilesAfterEnv` option in your Jest configuration (it's usually located either in `package.json` under the `"jest"` key or in a `jest.config.json` file):
68
68
 
69
69
  ```json
70
70
  {
@@ -75,9 +75,9 @@ Then automatically add it to your jest tests by using `setupFilesAfterEnv` optio
75
75
 
76
76
  ### Custom Jest Preset (React Native before 0.71)
77
77
 
78
- We generally advise to use the "react-native" preset when testing with this library.
78
+ We generally advise using the "react-native" preset when testing with this library.
79
79
 
80
- However, if you use React Native version earlier than 0.71 with [modern Jest fake timers](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers) (default since Jest 27), you'll need to apply this custom Jest preset or otherwise awaiting promises, like using `waitFor` or `findBy*`, queries will fail with timeout.
80
+ However, if you use React Native version earlier than 0.71 with [modern Jest fake timers](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers) (default since Jest 27), you'll need to apply this custom Jest preset or otherwise awaiting promises, like using `waitFor` or `findBy*`, queries will fail with a timeout.
81
81
 
82
82
  This is a [known issue](https://github.com/facebook/react-native/issues/29303). It happens because React Native's Jest preset overrides native Promise. Our preset restores it to defaults, which is not a problem in most apps out there.
83
83
 
@@ -124,17 +124,17 @@ test('form submits two answers', () => {
124
124
  });
125
125
  ```
126
126
 
127
- You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.js).
127
+ You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
128
128
 
129
129
  ## API / Usage
130
130
 
131
131
  The [public API](https://callstack.github.io/react-native-testing-library/docs/api) of `@testing-library/react-native` is focused around these essential methods:
132
132
 
133
- - [`render`](https://callstack.github.io/react-native-testing-library/docs/api#render) – deeply renders given React element and returns helpers to query the output components.
133
+ - [`render`](https://callstack.github.io/react-native-testing-library/docs/api#render) – deeply renders the given React element and returns helpers to query the output components.
134
134
  - [`fireEvent`](https://callstack.github.io/react-native-testing-library/docs/api#fireevent) - invokes named event handler on the element.
135
- - [`waitFor`](https://callstack.github.io/react-native-testing-library/docs/api#waitfor) - waits for non-deterministic periods of time until queried element is added or times out.
136
- - [`waitForElementToBeRemoved`](https://callstack.github.io/react-native-testing-library/docs/api#waitforelementtoberemoved) - waits for non-deterministic periods of time until queried element is removed or times out.
137
- - [`within`](https://callstack.github.io/react-native-testing-library/docs/api#within) - creates a queries object scoped for given element.
135
+ - [`waitFor`](https://callstack.github.io/react-native-testing-library/docs/api#waitfor) - waits for non-deterministic periods of time until the queried element is added or times out.
136
+ - [`waitForElementToBeRemoved`](https://callstack.github.io/react-native-testing-library/docs/api#waitforelementtoberemoved) - waits for non-deterministic periods of time until the queried element is removed or times out.
137
+ - [`within`](https://callstack.github.io/react-native-testing-library/docs/api#within) - creates a queries object scoped for a given element.
138
138
 
139
139
  ## Migration Guides
140
140
 
@@ -150,7 +150,7 @@ The [public API](https://callstack.github.io/react-native-testing-library/docs/a
150
150
 
151
151
  ## Related External Resources
152
152
 
153
- - [Real world extensive examples repo](https://github.com/vanGalilea/react-native-testing)
153
+ - [Real-world extensive examples repo](https://github.com/vanGalilea/react-native-testing)
154
154
  - [Where and how to start testing 🧪 your react-native app ⚛️ and how to keep on testin’](https://blog.usejournal.com/where-and-how-to-start-testing-your-react-native-app-%EF%B8%8F-and-how-to-keep-on-testin-ec3464fb9b41)
155
155
  - [Intro to React Native Testing Library & Jest Native](https://youtu.be/CpTQb0XWlRc)
156
156
 
@@ -52,6 +52,8 @@ function findEventHandler(element, eventName, nearestTouchResponder) {
52
52
  const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
53
53
  const handler = getEventHandler(element, eventName);
54
54
  if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;
55
+
56
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
55
57
  if (element.parent === null || element.parent.parent === null) {
56
58
  return null;
57
59
  }
@@ -81,7 +83,7 @@ function fireEvent(element, eventName, ...data) {
81
83
  return;
82
84
  }
83
85
  let returnValue;
84
- (0, _act.default)(() => {
86
+ void (0, _act.default)(() => {
85
87
  returnValue = handler(...data);
86
88
  });
87
89
  return returnValue;
@@ -1 +1 @@
1
- {"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","obj","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","returnValue","act","press","changeText","scroll","_default","exports"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return (\n Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element)\n );\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (\n eventsAffectedByPointerEventsProp.has(eventName) &&\n !isPointerEventEnabled(element)\n ) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance\n): EventHandler | null {\n const touchResponder = isTouchResponder(element)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder))\n return handler;\n\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n\n// Allows any string but will provide autocomplete for type T\ntype StringWithAutoComplete<T> = T | (string & Record<never, never>);\n\n// String union type of keys of T that start with on, stripped from on\ntype OnKeys<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}`\n ? Uncapitalize<Rest>\n : never]: T[K];\n};\n\ntype EventName = StringWithAutoComplete<\n | OnKeys<ViewProps>\n | OnKeys<TextProps>\n | OnKeys<TextInputProps>\n | OnKeys<PressableProps>\n | OnKeys<ScrollViewProps>\n>;\n\nfunction fireEvent(\n element: ReactTestInstance,\n eventName: EventName,\n ...data: unknown[]\n) {\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n"],"mappings":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAA2D,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIpD,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OACEE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AAEhF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAA0B,EAC1BU,SAAiB,EACjBC,qBAAyC,EACzC;EACA,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC1C,OACE,IAAAC,8BAAmB,EAACD,qBAAqB,CAAC,IAC1CH,mCAAmC,CAACK,GAAG,CAACH,SAAS,CAAC;EAEtD;EAEA,IACEJ,iCAAiC,CAACO,GAAG,CAACH,SAAS,CAAC,IAChD,CAAC,IAAAI,oCAAqB,EAACd,OAAO,CAAC,EAC/B;IACA,OAAO,KAAK;EACd;EAEA,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mBA,CAACf,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACgB,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEjB,SAAS,CAACkB,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE;;AAEA;;AAGA;;AAeA,SAASC,SAASA,CAChB7B,OAA0B,EAC1BU,SAAoB,EACpB,GAAGoB,IAAe,EAClB;EACA,MAAMT,OAAO,GAAGF,gBAAgB,CAACnB,OAAO,EAAEU,SAAS,CAAC;EACpD,IAAI,CAACW,OAAO,EAAE;IACZ;EACF;EAEA,IAAIU,WAAW;EACf,IAAAC,YAAG,EAAC,MAAM;IACRD,WAAW,GAAGV,OAAO,CAAC,GAAGS,IAAI,CAAC;EAChC,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB;AAEAF,SAAS,CAACI,KAAK,GAAG,CAACjC,OAA0B,EAAE,GAAG8B,IAAe,KAC/DD,SAAS,CAAC7B,OAAO,EAAE,OAAO,EAAE,GAAG8B,IAAI,CAAC;AAEtCD,SAAS,CAACK,UAAU,GAAG,CAAClC,OAA0B,EAAE,GAAG8B,IAAe,KACpED,SAAS,CAAC7B,OAAO,EAAE,YAAY,EAAE,GAAG8B,IAAI,CAAC;AAE3CD,SAAS,CAACM,MAAM,GAAG,CAACnC,OAA0B,EAAE,GAAG8B,IAAe,KAChED,SAAS,CAAC7B,OAAO,EAAE,QAAQ,EAAE,GAAG8B,IAAI,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAvC,OAAA,GAEzB+B,SAAS"}
1
+ {"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","obj","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","returnValue","act","press","changeText","scroll","_default","exports"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return (\n Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element)\n );\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (\n eventsAffectedByPointerEventsProp.has(eventName) &&\n !isPointerEventEnabled(element)\n ) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance\n): EventHandler | null {\n const touchResponder = isTouchResponder(element)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder))\n return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n\n// Allows any string but will provide autocomplete for type T\ntype StringWithAutoComplete<T> = T | (string & Record<never, never>);\n\n// String union type of keys of T that start with on, stripped from on\ntype OnKeys<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}`\n ? Uncapitalize<Rest>\n : never]: T[K];\n};\n\ntype EventName = StringWithAutoComplete<\n | OnKeys<ViewProps>\n | OnKeys<TextProps>\n | OnKeys<TextInputProps>\n | OnKeys<PressableProps>\n | OnKeys<ScrollViewProps>\n>;\n\nfunction fireEvent(\n element: ReactTestInstance,\n eventName: EventName,\n ...data: unknown[]\n) {\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll',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Q,KAAIA,SAAS,CAACgB,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEjB,SAAS,CAACkB,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE;;AAEA;;AAGA;;AAeA,SAASC,SAASA,CAChB7B,OAA0B,EAC1BU,SAAoB,EACpB,GAAGoB,IAAe,EAClB;EACA,MAAMT,OAAO,GAAGF,gBAAgB,CAACnB,OAAO,EAAEU,SAAS,CAAC;EACpD,IAAI,CAACW,OAAO,EAAE;IACZ;EACF;EAEA,IAAIU,WAAW;EACf,KAAK,IAAAC,YAAG,EAAC,MAAM;IACbD,WAAW,GAAGV,OAAO,CAAC,GAAGS,IAAI,CAAC;EAChC,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB;AAEAF,SAAS,CAACI,KAAK,GAAG,CAACjC,OAA0B,EAAE,GAAG8B,IAAe,KAC/DD,SAAS,CAAC7B,OAAO,EAAE,OAAO,EAAE,GAAG8B,IAAI,CAAC;AAEtCD,SAAS,CAACK,UAAU,GAAG,CAAClC,OAA0B,EAAE,GAAG8B,IAAe,KACpED,SAAS,CAAC7B,OAAO,EAAE,YAAY,EAAE,GAAG8B,IAAI,CAAC;AAE3CD,SAAS,CAACM,MAAM,GAAG,CAACnC,OAA0B,EAAE,GAAG8B,IAAe,KAChED,SAAS,CAAC7B,OAAO,EAAE,QAAQ,EAAE,GAAG8B,IAAI,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAvC,OAAA,GAEzB+B,SAAS"}
@@ -20,4 +20,5 @@ export declare function isElementBusy(element: ReactTestInstance): NonNullable<A
20
20
  export declare function isElementCollapsed(element: ReactTestInstance): NonNullable<AccessibilityState['expanded']>;
21
21
  export declare function isElementExpanded(element: ReactTestInstance): NonNullable<AccessibilityState['expanded']>;
22
22
  export declare function isElementSelected(element: ReactTestInstance): NonNullable<AccessibilityState['selected']>;
23
+ export declare function getAccessibleName(element: ReactTestInstance): string | undefined;
23
24
  export {};
@@ -11,6 +11,7 @@ exports.getAccessibilityRole = getAccessibilityRole;
11
11
  exports.getAccessibilityState = getAccessibilityState;
12
12
  exports.getAccessibilityValue = getAccessibilityValue;
13
13
  exports.getAccessibilityViewIsModal = getAccessibilityViewIsModal;
14
+ exports.getAccessibleName = getAccessibleName;
14
15
  exports.isAccessibilityElement = isAccessibilityElement;
15
16
  exports.isElementBusy = isElementBusy;
16
17
  exports.isElementCollapsed = isElementCollapsed;
@@ -19,6 +20,7 @@ exports.isElementSelected = isElementSelected;
19
20
  exports.isHiddenFromAccessibility = isHiddenFromAccessibility;
20
21
  exports.isInaccessible = void 0;
21
22
  var _reactNative = require("react-native");
23
+ var _textContent = require("./text-content");
22
24
  var _componentTree = require("./component-tree");
23
25
  var _hostComponentNames = require("./host-component-names");
24
26
  const accessibilityStateKeys = exports.accessibilityStateKeys = ['disabled', 'selected', 'checked', 'busy', 'expanded'];
@@ -178,4 +180,21 @@ function isElementSelected(element) {
178
180
  } = element.props;
179
181
  return ariaSelected ?? accessibilityState?.selected ?? false;
180
182
  }
183
+ function getAccessibleName(element) {
184
+ const label = getAccessibilityLabel(element);
185
+ if (label) {
186
+ return label;
187
+ }
188
+ const labelElementId = getAccessibilityLabelledBy(element);
189
+ if (labelElementId) {
190
+ const rootElement = (0, _componentTree.getUnsafeRootElement)(element);
191
+ const labelElement = rootElement?.findByProps({
192
+ nativeID: labelElementId
193
+ });
194
+ if (labelElement) {
195
+ return (0, _textContent.getTextContent)(labelElement);
196
+ }
197
+ }
198
+ return (0, _textContent.getTextContent)(element);
199
+ }
181
200
  //# sourceMappingURL=accessiblity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessiblity.js","names":["_reactNative","require","_componentTree","_hostComponentNames","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","getAccessibilityViewIsModal","isAccessibilityElement","accessible","hostComponentNames","getHostComponentNames","type","text","textInput","switch","getAccessibilityRole","role","accessibilityRole","accessibilityViewIsModal","getAccessibilityLabel","accessibilityLabel","getAccessibilityLabelledBy","accessibilityLabelledBy","getAccessibilityState","accessibilityState","ariaBusy","ariaChecked","ariaDisabled","ariaExpanded","ariaSelected","hasAnyAccessibilityStateProps","busy","checked","disabled","expanded","selected","getAccessibilityCheckedState","getAccessibilityValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","hasAnyAccessibilityValueProps","max","min","now","isElementBusy","isElementCollapsed","isElementExpanded","isElementSelected"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import {\n AccessibilityState,\n AccessibilityValue,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\nimport { getHostComponentNames } from './host-component-names';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessiblityValueKeys: (keyof AccessibilityValue)[] = [\n 'min',\n 'max',\n 'now',\n 'text',\n];\n\nexport function isHiddenFromAccessibility(\n element: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {}\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatitibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: ReactTestInstance): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => getAccessibilityViewIsModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(\n element: ReactTestInstance | null\n): boolean {\n if (element == null) {\n return false;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n const hostComponentNames = getHostComponentNames();\n return (\n element?.type === hostComponentNames?.text ||\n element?.type === hostComponentNames?.textInput ||\n element?.type === hostComponentNames?.switch\n );\n}\n\nexport function getAccessibilityRole(\n element: ReactTestInstance\n): string | undefined {\n return element.props.role ?? element.props.accessibilityRole;\n}\n\nexport function getAccessibilityViewIsModal(element: ReactTestInstance) {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function getAccessibilityLabel(\n element: ReactTestInstance\n): string | undefined {\n return element.props['aria-label'] ?? element.props.accessibilityLabel;\n}\n\nexport function getAccessibilityLabelledBy(\n element: ReactTestInstance\n): string | undefined {\n return (\n element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy\n );\n}\n\nexport function getAccessibilityState(\n element: ReactTestInstance\n): AccessibilityState | undefined {\n const {\n accessibilityState,\n 'aria-busy': ariaBusy,\n 'aria-checked': ariaChecked,\n 'aria-disabled': ariaDisabled,\n 'aria-expanded': ariaExpanded,\n 'aria-selected': ariaSelected,\n } = element.props;\n\n const hasAnyAccessibilityStateProps =\n accessibilityState != null ||\n ariaBusy != null ||\n ariaChecked != null ||\n ariaDisabled != null ||\n ariaExpanded != null ||\n ariaSelected != null;\n\n if (!hasAnyAccessibilityStateProps) {\n return undefined;\n }\n\n return {\n busy: ariaBusy ?? accessibilityState?.busy,\n checked: ariaChecked ?? accessibilityState?.checked,\n disabled: ariaDisabled ?? accessibilityState?.disabled,\n expanded: ariaExpanded ?? accessibilityState?.expanded,\n selected: ariaSelected ?? accessibilityState?.selected,\n };\n}\n\nexport function getAccessibilityCheckedState(\n element: ReactTestInstance\n): AccessibilityState['checked'] {\n const { accessibilityState, 'aria-checked': ariaChecked } = element.props;\n return ariaChecked ?? accessibilityState?.checked;\n}\n\nexport function getAccessibilityValue(\n element: ReactTestInstance\n): AccessibilityValue | undefined {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n const hasAnyAccessibilityValueProps =\n accessibilityValue != null ||\n ariaValueMax != null ||\n ariaValueMin != null ||\n ariaValueNow != null ||\n ariaValueText != null;\n\n if (!hasAnyAccessibilityValueProps) {\n return undefined;\n }\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function isElementBusy(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['busy']> {\n const { accessibilityState, 'aria-busy': ariaBusy } = element.props;\n return ariaBusy ?? accessibilityState?.busy ?? false;\n}\n\nexport function isElementCollapsed(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return (ariaExpanded ?? accessibilityState?.expanded) === false;\n}\n\nexport function isElementExpanded(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return ariaExpanded ?? accessibilityState?.expanded ?? false;\n}\n\nexport function isElementSelected(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['selected']> {\n const { accessibilityState, 'aria-selected': ariaSelected } = element.props;\n return ariaSelected ?? accessibilityState?.selected ?? false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAMO,MAAMG,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,qBAAmD,GAAAD,OAAA,CAAAC,qBAAA,GAAG,CACjE,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,CACP;AAEM,SAASC,yBAAyBA,CACvCC,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ,OAAO,CAAC;MAC7DD,KAAK,EAAEM,GAAG,CAACL,OAAO,EAAEC,4BAA4B,CAAC;IACnD;IAEA,IAAIA,4BAA4B,EAAE;MAChC,OAAO,IAAI;IACb;IAEAD,OAAO,GAAGA,OAAO,CAACM,MAAM;EAC1B;EAEA,OAAO,KAAK;A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AK;AACtD;AAEO,SAASiB,kBAAkBA,CAChChE,OAA0B,EACmB;EAC7C,MAAM;IAAEwC,kBAAkB;IAAE,eAAe,EAAEI;EAAa,CAAC,GAAG5C,OAAO,CAACU,KAAK;EAC3E,OAAO,CAACkC,YAAY,IAAIJ,kBAAkB,EAAEU,QAAQ,MAAM,KAAK;AACjE;AAEO,SAASe,iBAAiBA,CAC/BjE,OAA0B,EACmB;EAC7C,MAAM;IAAEwC,kBAAkB;IAAE,eAAe,EAAEI;EAAa,CAAC,GAAG5C,OAAO,CAACU,KAAK;EAC3E,OAAOkC,YAAY,IAAIJ,kBAAkB,EAAEU,QAAQ,IAAI,KAAK;AAC9D;AAEO,SAASgB,iBAAiBA,CAC/BlE,OAA0B,EACmB;EAC7C,MAAM;IAAEwC,kBAAkB;IAAE,eAAe,EAAEK;EAAa,CAAC,GAAG7C,OAAO,CAACU,KAAK;EAC3E,OAAOmC,YAAY,IAAIL,kBAAkB,EAAEW,QAAQ,IAAI,KAAK;AAC9D"}
1
+ {"version":3,"file":"accessiblity.js","names":["_reactNative","require","_textContent","_componentTree","_hostComponentNames","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","getAccessibilityViewIsModal","isAccessibilityElement","accessible","hostComponentNames","getHostComponentNames","type","text","textInput","switch","getAccessibilityRole","role","accessibilityRole","accessibilityViewIsModal","getAccessibilityLabel","accessibilityLabel","getAccessibilityLabelledBy","accessibilityLabelledBy","getAccessibilityState","accessibilityState","ariaBusy","ariaChecked","ariaDisabled","ariaExpanded","ariaSelected","hasAnyAccessibilityStateProps","busy","checked","disabled","expanded","selected","getAccessibilityCheckedState","getAccessibilityValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","hasAnyAccessibilityValueProps","max","min","now","isElementBusy","isElementCollapsed","isElementExpanded","isElementSelected","getAccessibleName","label","labelElementId","rootElement","getUnsafeRootElement","labelElement","findByProps","nativeID","getTextContent"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import {\n AccessibilityState,\n AccessibilityValue,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getTextContent } from './text-content';\nimport { getHostSiblings, getUnsafeRootElement } from './component-tree';\nimport { getHostComponentNames } from './host-component-names';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessiblityValueKeys: (keyof AccessibilityValue)[] = [\n 'min',\n 'max',\n 'now',\n 'text',\n];\n\nexport function isHiddenFromAccessibility(\n element: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {}\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatitibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: ReactTestInstance): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => getAccessibilityViewIsModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(\n element: ReactTestInstance | null\n): boolean {\n if (element == null) {\n return false;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n const hostComponentNames = getHostComponentNames();\n return (\n element?.type === hostComponentNames?.text ||\n element?.type === hostComponentNames?.textInput ||\n element?.type === hostComponentNames?.switch\n );\n}\n\nexport function getAccessibilityRole(\n element: ReactTestInstance\n): string | undefined {\n return element.props.role ?? element.props.accessibilityRole;\n}\n\nexport function getAccessibilityViewIsModal(element: ReactTestInstance) {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function getAccessibilityLabel(\n element: ReactTestInstance\n): string | undefined {\n return element.props['aria-label'] ?? element.props.accessibilityLabel;\n}\n\nexport function getAccessibilityLabelledBy(\n element: ReactTestInstance\n): string | undefined {\n return (\n element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy\n );\n}\n\nexport function getAccessibilityState(\n element: ReactTestInstance\n): AccessibilityState | undefined {\n const {\n accessibilityState,\n 'aria-busy': ariaBusy,\n 'aria-checked': ariaChecked,\n 'aria-disabled': ariaDisabled,\n 'aria-expanded': ariaExpanded,\n 'aria-selected': ariaSelected,\n } = element.props;\n\n const hasAnyAccessibilityStateProps =\n accessibilityState != null ||\n ariaBusy != null ||\n ariaChecked != null ||\n ariaDisabled != null ||\n ariaExpanded != null ||\n ariaSelected != null;\n\n if (!hasAnyAccessibilityStateProps) {\n return undefined;\n }\n\n return {\n busy: ariaBusy ?? accessibilityState?.busy,\n checked: ariaChecked ?? accessibilityState?.checked,\n disabled: ariaDisabled ?? accessibilityState?.disabled,\n expanded: ariaExpanded ?? accessibilityState?.expanded,\n selected: ariaSelected ?? accessibilityState?.selected,\n };\n}\n\nexport function getAccessibilityCheckedState(\n element: ReactTestInstance\n): AccessibilityState['checked'] {\n const { accessibilityState, 'aria-checked': ariaChecked } = element.props;\n return ariaChecked ?? accessibilityState?.checked;\n}\n\nexport function getAccessibilityValue(\n element: ReactTestInstance\n): AccessibilityValue | undefined {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n const hasAnyAccessibilityValueProps =\n accessibilityValue != null ||\n ariaValueMax != null ||\n ariaValueMin != null ||\n ariaValueNow != null ||\n ariaValueText != null;\n\n if (!hasAnyAccessibilityValueProps) {\n return undefined;\n }\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function isElementBusy(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['busy']> {\n const { accessibilityState, 'aria-busy': ariaBusy } = element.props;\n return ariaBusy ?? accessibilityState?.busy ?? false;\n}\n\nexport function isElementCollapsed(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return (ariaExpanded ?? accessibilityState?.expanded) === false;\n}\n\nexport function isElementExpanded(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['expanded']> {\n const { accessibilityState, 'aria-expanded': ariaExpanded } = element.props;\n return ariaExpanded ?? accessibilityState?.expanded ?? false;\n}\n\nexport function isElementSelected(\n element: ReactTestInstance\n): NonNullable<AccessibilityState['selected']> {\n const { accessibilityState, 'aria-selected': ariaSelected } = element.props;\n return ariaSelected ?? accessibilityState?.selected ?? false;\n}\n\nexport function getAccessibleName(\n element: ReactTestInstance\n): string | undefined {\n const label = getAccessibilityLabel(element);\n if (label) {\n return label;\n }\n\n const labelElementId = getAccessibilityLabelledBy(element);\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = rootElement?.findByProps({ nativeID: labelElementId });\n if (labelElement) {\n return getTextContent(labelElement);\n }\n }\n\n return getTextContent(element);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAMO,MAAMI,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,qBAAmD,GAAAD,OAAA,CAAAC,qBAAA,GAAG,CACjE,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,CACP;AAEM,SAASC,yBAAyBA,CACvCC,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ,OAAO,CAAC;MAC7DD,KAAK,EAAEM,GAAG,CAACL,OAAO,EAAEC,4BAA4B,CAAC;IACnD;IAEA,IAAIA,4BAA4B,EAAE;MAChC,OAAO,IAAI;IACb;IAEAD,OAAO,GAAGA,OAAO,CAACM,MAAM;EAC1B;EAEA,OAAO,KAAK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icroTasks = require("./flush-micro-tasks");
18
18
  var _act = require("./act");
19
- if (typeof process === 'undefined' || !process.env?.RNTL_SKIP_AUTO_CLEANUP) {
19
+ if (!process?.env?.RNTL_SKIP_AUTO_CLEANUP) {
20
20
  // If we're running in a test runner that supports afterEach
21
21
  // then we'll automatically run cleanup afterEach test
22
22
  // this ensures that tests run in isolation from each other
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_pure","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_flushMicroTasks","_act","process","env","RNTL_SKIP_AUTO_CLEANUP","afterEach","flushMicroTasksLegacy","cleanup","beforeAll","afterAll","previousIsReactActEnvironment","getIsReactActEnvironment","setReactActEnvironment"],"sources":["../src/index.ts"],"sourcesContent":["import { cleanup } from './pure';\nimport { flushMicroTasksLegacy } from './flush-micro-tasks';\nimport { getIsReactActEnvironment, setReactActEnvironment } from './act';\n\nif (typeof process === 'undefined' || !process.env?.RNTL_SKIP_AUTO_CLEANUP) {\n // If we're running in a test runner that supports afterEach\n // then we'll automatically run cleanup afterEach test\n // this ensures that tests run in isolation from each other\n // if you don't like this then either import the `pure` module\n // or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.\n if (typeof afterEach === 'function') {\n // eslint-disable-next-line no-undef\n afterEach(async () => {\n await flushMicroTasksLegacy();\n cleanup();\n });\n }\n\n if (typeof beforeAll === 'function' && typeof afterAll === 'function') {\n // This matches the behavior of React < 18.\n let previousIsReactActEnvironment = getIsReactActEnvironment();\n beforeAll(() => {\n previousIsReactActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(true);\n });\n\n afterAll(() => {\n setReactActEnvironment(previousIsReactActEnvironment);\n });\n }\n}\n\nexport * from './pure';\n"],"mappings":";;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAgCAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AA/BA,IAAAK,gBAAA,GAAAT,OAAA;AACA,IAAAU,IAAA,GAAAV,OAAA;AAEA,IAAI,OAAOW,OAAO,KAAK,WAAW,IAAI,CAACA,OAAO,CAACC,GAAG,EAAEC,sBAAsB,EAAE;EAC1E;EACA;EACA;EACA;EACA;EACA,IAAI,OAAOC,SAAS,KAAK,UAAU,EAAE;IACnC;IACAA,SAAS,CAAC,YAAY;MACpB,MAAM,IAAAC,sCAAqB,EAAC,CAAC;MAC7B,IAAAC,aAAO,EAAC,CAAC;IACX,CAAC,CAAC;EACJ;EAEA,IAAI,OAAOC,SAAS,KAAK,UAAU,IAAI,OAAOC,QAAQ,KAAK,UAAU,EAAE;IACrE;IACA,IAAIC,6BAA6B,GAAG,IAAAC,6BAAwB,EAAC,CAAC;IAC9DH,SAAS,CAAC,MAAM;MACdE,6BAA6B,GAAG,IAAAC,6BAAwB,EAAC,CAAC;MAC1D,IAAAC,2BAAsB,EAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEFH,QAAQ,CAAC,MAAM;MACb,IAAAG,2BAAsB,EAACF,6BAA6B,CAAC;IACvD,CAAC,CAAC;EACJ;AACF"}
1
+ {"version":3,"file":"index.js","names":["_pure","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_flushMicroTasks","_act","process","env","RNTL_SKIP_AUTO_CLEANUP","afterEach","flushMicroTasksLegacy","cleanup","beforeAll","afterAll","previousIsReactActEnvironment","getIsReactActEnvironment","setReactActEnvironment"],"sources":["../src/index.ts"],"sourcesContent":["import { cleanup } from './pure';\nimport { flushMicroTasksLegacy } from './flush-micro-tasks';\nimport { getIsReactActEnvironment, setReactActEnvironment } from './act';\n\nif (!process?.env?.RNTL_SKIP_AUTO_CLEANUP) {\n // If we're running in a test runner that supports afterEach\n // then we'll automatically run cleanup afterEach test\n // this ensures that tests run in isolation from each other\n // if you don't like this then either import the `pure` module\n // or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.\n if (typeof afterEach === 'function') {\n // eslint-disable-next-line no-undef\n afterEach(async () => {\n await flushMicroTasksLegacy();\n cleanup();\n });\n }\n\n if (typeof beforeAll === 'function' && typeof afterAll === 'function') {\n // This matches the behavior of React < 18.\n let previousIsReactActEnvironment = getIsReactActEnvironment();\n beforeAll(() => {\n previousIsReactActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(true);\n });\n\n afterAll(() => {\n setReactActEnvironment(previousIsReactActEnvironment);\n });\n }\n}\n\nexport * from './pure';\n"],"mappings":";;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAgCAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AA/BA,IAAAK,gBAAA,GAAAT,OAAA;AACA,IAAAU,IAAA,GAAAV,OAAA;AAEA,IAAI,CAACW,OAAO,EAAEC,GAAG,EAAEC,sBAAsB,EAAE;EACzC;EACA;EACA;EACA;EACA;EACA,IAAI,OAAOC,SAAS,KAAK,UAAU,EAAE;IACnC;IACAA,SAAS,CAAC,YAAY;MACpB,MAAM,IAAAC,sCAAqB,EAAC,CAAC;MAC7B,IAAAC,aAAO,EAAC,CAAC;IACX,CAAC,CAAC;EACJ;EAEA,IAAI,OAAOC,SAAS,KAAK,UAAU,IAAI,OAAOC,QAAQ,KAAK,UAAU,EAAE;IACrE;IACA,IAAIC,6BAA6B,GAAG,IAAAC,6BAAwB,EAAC,CAAC;IAC9DH,SAAS,CAAC,MAAM;MACdE,6BAA6B,GAAG,IAAAC,6BAAwB,EAAC,CAAC;MAC1D,IAAAC,2BAAsB,EAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEFH,QAAQ,CAAC,MAAM;MACb,IAAAG,2BAAsB,EAACF,6BAA6B,CAAC;IACvD,CAAC,CAAC;EACJ;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"extend-expect.d.js","names":[],"sources":["../../src/matchers/extend-expect.d.ts"],"sourcesContent":["import type { StyleProp } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport type { Style } from './to-have-style';\n\nexport interface JestNativeMatchers<R> {\n toBeOnTheScreen(): R;\n toBeChecked(): R;\n toBeCollapsed(): R;\n toBeDisabled(): R;\n toBeBusy(): R;\n toBeEmptyElement(): R;\n toBeEnabled(): R;\n toBeExpanded(): R;\n toBePartiallyChecked(): R;\n toBeSelected(): R;\n toBeVisible(): R;\n toContainElement(element: ReactTestInstance | null): R;\n toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;\n toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;\n toHaveProp(name: string, expectedValue?: unknown): R;\n toHaveStyle(style: StyleProp<Style>): R;\n toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;\n}\n\n// Implicit Jest global `expect`.\ndeclare global {\n namespace jest {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}\n }\n}\n\n// Explicit `@jest/globals` `expect` matchers.\ndeclare module '@jest/expect' {\n interface Matchers<R extends void | Promise<void>>\n extends JestNativeMatchers<R> {}\n}\n"],"mappings":""}
1
+ {"version":3,"file":"extend-expect.d.js","names":[],"sources":["../../src/matchers/extend-expect.d.ts"],"sourcesContent":["import type { StyleProp } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport type { Style } from './to-have-style';\n\nexport interface JestNativeMatchers<R> {\n toBeOnTheScreen(): R;\n toBeChecked(): R;\n toBeCollapsed(): R;\n toBeDisabled(): R;\n toBeBusy(): R;\n toBeEmptyElement(): R;\n toBeEnabled(): R;\n toBeExpanded(): R;\n toBePartiallyChecked(): R;\n toBeSelected(): R;\n toBeVisible(): R;\n toContainElement(element: ReactTestInstance | null): R;\n toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;\n toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;\n toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;\n toHaveProp(name: string, expectedValue?: unknown): R;\n toHaveStyle(style: StyleProp<Style>): R;\n toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;\n}\n\n// Implicit Jest global `expect`.\ndeclare global {\n namespace jest {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}\n }\n}\n\n// Explicit `@jest/globals` `expect` matchers.\ndeclare module '@jest/expect' {\n interface Matchers<R extends void | Promise<void>>\n extends JestNativeMatchers<R> {}\n}\n"],"mappings":""}
@@ -12,6 +12,7 @@ var _toBeSelected = require("./to-be-selected");
12
12
  var _toBeVisible = require("./to-be-visible");
13
13
  var _toContainElement = require("./to-contain-element");
14
14
  var _toHaveAccessibilityValue = require("./to-have-accessibility-value");
15
+ var _toHaveAccessibleName = require("./to-have-accessible-name");
15
16
  var _toHaveDisplayValue = require("./to-have-display-value");
16
17
  var _toHaveProp = require("./to-have-prop");
17
18
  var _toHaveStyle = require("./to-have-style");
@@ -32,6 +33,7 @@ expect.extend({
32
33
  toBeVisible: _toBeVisible.toBeVisible,
33
34
  toContainElement: _toContainElement.toContainElement,
34
35
  toHaveAccessibilityValue: _toHaveAccessibilityValue.toHaveAccessibilityValue,
36
+ toHaveAccessibleName: _toHaveAccessibleName.toHaveAccessibleName,
35
37
  toHaveDisplayValue: _toHaveDisplayValue.toHaveDisplayValue,
36
38
  toHaveProp: _toHaveProp.toHaveProp,
37
39
  toHaveStyle: _toHaveStyle.toHaveStyle,
@@ -1 +1 @@
1
- {"version":3,"file":"extend-expect.js","names":["_toBeOnTheScreen","require","_toBeChecked","_toBeCollapsed","_toBeDisabled","_toBeBusy","_toBeEmptyElement","_toBeExpanded","_toBePartiallyChecked","_toBeSelected","_toBeVisible","_toContainElement","_toHaveAccessibilityValue","_toHaveDisplayValue","_toHaveProp","_toHaveStyle","_toHaveTextContent","expect","extend","toBeOnTheScreen","toBeChecked","toBeCollapsed","toBeDisabled","toBeBusy","toBeEmptyElement","toBeEnabled","toBeExpanded","toBePartiallyChecked","toBeSelected","toBeVisible","toContainElement","toHaveAccessibilityValue","toHaveDisplayValue","toHaveProp","toHaveStyle","toHaveTextContent"],"sources":["../../src/matchers/extend-expect.ts"],"sourcesContent":["/// <reference path=\"./extend-expect.d.ts\" />\n\nimport { toBeOnTheScreen } from './to-be-on-the-screen';\nimport { toBeChecked } from './to-be-checked';\nimport { toBeCollapsed } from './to-be-collapsed';\nimport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nimport { toBeBusy } from './to-be-busy';\nimport { toBeEmptyElement } from './to-be-empty-element';\nimport { toBeExpanded } from './to-be-expanded';\nimport { toBePartiallyChecked } from './to-be-partially-checked';\nimport { toBeSelected } from './to-be-selected';\nimport { toBeVisible } from './to-be-visible';\nimport { toContainElement } from './to-contain-element';\nimport { toHaveAccessibilityValue } from './to-have-accessibility-value';\nimport { toHaveDisplayValue } from './to-have-display-value';\nimport { toHaveProp } from './to-have-prop';\nimport { toHaveStyle } from './to-have-style';\nimport { toHaveTextContent } from './to-have-text-content';\n\nexpect.extend({\n toBeOnTheScreen,\n toBeChecked,\n toBeCollapsed,\n toBeDisabled,\n toBeBusy,\n toBeEmptyElement,\n toBeEnabled,\n toBeExpanded,\n toBePartiallyChecked,\n toBeSelected,\n toBeVisible,\n toContainElement,\n toHaveAccessibilityValue,\n toHaveDisplayValue,\n toHaveProp,\n toHaveStyle,\n toHaveTextContent,\n});\n"],"mappings":";;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,yBAAA,GAAAX,OAAA;AACA,IAAAY,mBAAA,GAAAZ,OAAA;AACA,IAAAa,WAAA,GAAAb,OAAA;AACA,IAAAc,YAAA,GAAAd,OAAA;AACA,IAAAe,kBAAA,GAAAf,OAAA;AAjBA;;AAmBAgB,MAAM,CAACC,MAAM,CAAC;EACZC,eAAe,EAAfA,gCAAe;EACfC,WAAW,EAAXA,wBAAW;EACXC,aAAa,EAAbA,4BAAa;EACbC,YAAY,EAAZA,0BAAY;EACZC,QAAQ,EAARA,kBAAQ;EACRC,gBAAgB,EAAhBA,kCAAgB;EAChBC,WAAW,EAAXA,yBAAW;EACXC,YAAY,EAAZA,0BAAY;EACZC,oBAAoB,EAApBA,0CAAoB;EACpBC,YAAY,EAAZA,0BAAY;EACZC,WAAW,EAAXA,wBAAW;EACXC,gBAAgB,EAAhBA,kCAAgB;EAChBC,wBAAwB,EAAxBA,kDAAwB;EACxBC,kBAAkB,EAAlBA,sCAAkB;EAClBC,UAAU,EAAVA,sBAAU;EACVC,WAAW,EAAXA,wBAAW;EACXC,iBAAiB,EAAjBA;AACF,CAAC,CAAC"}
1
+ {"version":3,"file":"extend-expect.js","names":["_toBeOnTheScreen","require","_toBeChecked","_toBeCollapsed","_toBeDisabled","_toBeBusy","_toBeEmptyElement","_toBeExpanded","_toBePartiallyChecked","_toBeSelected","_toBeVisible","_toContainElement","_toHaveAccessibilityValue","_toHaveAccessibleName","_toHaveDisplayValue","_toHaveProp","_toHaveStyle","_toHaveTextContent","expect","extend","toBeOnTheScreen","toBeChecked","toBeCollapsed","toBeDisabled","toBeBusy","toBeEmptyElement","toBeEnabled","toBeExpanded","toBePartiallyChecked","toBeSelected","toBeVisible","toContainElement","toHaveAccessibilityValue","toHaveAccessibleName","toHaveDisplayValue","toHaveProp","toHaveStyle","toHaveTextContent"],"sources":["../../src/matchers/extend-expect.ts"],"sourcesContent":["/// <reference path=\"./extend-expect.d.ts\" />\n\nimport { toBeOnTheScreen } from './to-be-on-the-screen';\nimport { toBeChecked } from './to-be-checked';\nimport { toBeCollapsed } from './to-be-collapsed';\nimport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nimport { toBeBusy } from './to-be-busy';\nimport { toBeEmptyElement } from './to-be-empty-element';\nimport { toBeExpanded } from './to-be-expanded';\nimport { toBePartiallyChecked } from './to-be-partially-checked';\nimport { toBeSelected } from './to-be-selected';\nimport { toBeVisible } from './to-be-visible';\nimport { toContainElement } from './to-contain-element';\nimport { toHaveAccessibilityValue } from './to-have-accessibility-value';\nimport { toHaveAccessibleName } from './to-have-accessible-name';\nimport { toHaveDisplayValue } from './to-have-display-value';\nimport { toHaveProp } from './to-have-prop';\nimport { toHaveStyle } from './to-have-style';\nimport { toHaveTextContent } from './to-have-text-content';\n\nexpect.extend({\n toBeOnTheScreen,\n toBeChecked,\n toBeCollapsed,\n toBeDisabled,\n toBeBusy,\n toBeEmptyElement,\n toBeEnabled,\n toBeExpanded,\n toBePartiallyChecked,\n toBeSelected,\n toBeVisible,\n toContainElement,\n toHaveAccessibilityValue,\n toHaveAccessibleName,\n toHaveDisplayValue,\n toHaveProp,\n toHaveStyle,\n toHaveTextContent,\n});\n"],"mappings":";;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,yBAAA,GAAAX,OAAA;AACA,IAAAY,qBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,WAAA,GAAAd,OAAA;AACA,IAAAe,YAAA,GAAAf,OAAA;AACA,IAAAgB,kBAAA,GAAAhB,OAAA;AAlBA;;AAoBAiB,MAAM,CAACC,MAAM,CAAC;EACZC,eAAe,EAAfA,gCAAe;EACfC,WAAW,EAAXA,wBAAW;EACXC,aAAa,EAAbA,4BAAa;EACbC,YAAY,EAAZA,0BAAY;EACZC,QAAQ,EAARA,kBAAQ;EACRC,gBAAgB,EAAhBA,kCAAgB;EAChBC,WAAW,EAAXA,yBAAW;EACXC,YAAY,EAAZA,0BAAY;EACZC,oBAAoB,EAApBA,0CAAoB;EACpBC,YAAY,EAAZA,0BAAY;EACZC,WAAW,EAAXA,wBAAW;EACXC,gBAAgB,EAAhBA,kCAAgB;EAChBC,wBAAwB,EAAxBA,kDAAwB;EACxBC,oBAAoB,EAApBA,0CAAoB;EACpBC,kBAAkB,EAAlBA,sCAAkB;EAClBC,UAAU,EAAVA,sBAAU;EACVC,WAAW,EAAXA,wBAAW;EACXC,iBAAiB,EAAjBA;AACF,CAAC,CAAC"}
@@ -10,6 +10,7 @@ export { toBeSelected } from './to-be-selected';
10
10
  export { toBeVisible } from './to-be-visible';
11
11
  export { toContainElement } from './to-contain-element';
12
12
  export { toHaveAccessibilityValue } from './to-have-accessibility-value';
13
+ export { toHaveAccessibleName } from './to-have-accessible-name';
13
14
  export { toHaveDisplayValue } from './to-have-display-value';
14
15
  export { toHaveProp } from './to-have-prop';
15
16
  export { toHaveStyle } from './to-have-style';
@@ -81,6 +81,12 @@ Object.defineProperty(exports, "toHaveAccessibilityValue", {
81
81
  return _toHaveAccessibilityValue.toHaveAccessibilityValue;
82
82
  }
83
83
  });
84
+ Object.defineProperty(exports, "toHaveAccessibleName", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _toHaveAccessibleName.toHaveAccessibleName;
88
+ }
89
+ });
84
90
  Object.defineProperty(exports, "toHaveDisplayValue", {
85
91
  enumerable: true,
86
92
  get: function () {
@@ -117,6 +123,7 @@ var _toBeSelected = require("./to-be-selected");
117
123
  var _toBeVisible = require("./to-be-visible");
118
124
  var _toContainElement = require("./to-contain-element");
119
125
  var _toHaveAccessibilityValue = require("./to-have-accessibility-value");
126
+ var _toHaveAccessibleName = require("./to-have-accessible-name");
120
127
  var _toHaveDisplayValue = require("./to-have-display-value");
121
128
  var _toHaveProp = require("./to-have-prop");
122
129
  var _toHaveStyle = require("./to-have-style");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_toBeBusy","require","_toBeChecked","_toBeCollapsed","_toBeDisabled","_toBeEmptyElement","_toBeExpanded","_toBeOnTheScreen","_toBePartiallyChecked","_toBeSelected","_toBeVisible","_toContainElement","_toHaveAccessibilityValue","_toHaveDisplayValue","_toHaveProp","_toHaveStyle","_toHaveTextContent"],"sources":["../../src/matchers/index.ts"],"sourcesContent":["export { toBeBusy } from './to-be-busy';\nexport { toBeChecked } from './to-be-checked';\nexport { toBeCollapsed } from './to-be-collapsed';\nexport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nexport { toBeEmptyElement } from './to-be-empty-element';\nexport { toBeExpanded } from './to-be-expanded';\nexport { toBeOnTheScreen } from './to-be-on-the-screen';\nexport { toBePartiallyChecked } from './to-be-partially-checked';\nexport { toBeSelected } from './to-be-selected';\nexport { toBeVisible } from './to-be-visible';\nexport { toContainElement } from './to-contain-element';\nexport { toHaveAccessibilityValue } from './to-have-accessibility-value';\nexport { toHaveDisplayValue } from './to-have-display-value';\nexport { toHaveProp } from './to-have-prop';\nexport { toHaveStyle } from './to-have-style';\nexport { toHaveTextContent } from './to-have-text-content';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,yBAAA,GAAAX,OAAA;AACA,IAAAY,mBAAA,GAAAZ,OAAA;AACA,IAAAa,WAAA,GAAAb,OAAA;AACA,IAAAc,YAAA,GAAAd,OAAA;AACA,IAAAe,kBAAA,GAAAf,OAAA"}
1
+ {"version":3,"file":"index.js","names":["_toBeBusy","require","_toBeChecked","_toBeCollapsed","_toBeDisabled","_toBeEmptyElement","_toBeExpanded","_toBeOnTheScreen","_toBePartiallyChecked","_toBeSelected","_toBeVisible","_toContainElement","_toHaveAccessibilityValue","_toHaveAccessibleName","_toHaveDisplayValue","_toHaveProp","_toHaveStyle","_toHaveTextContent"],"sources":["../../src/matchers/index.ts"],"sourcesContent":["export { toBeBusy } from './to-be-busy';\nexport { toBeChecked } from './to-be-checked';\nexport { toBeCollapsed } from './to-be-collapsed';\nexport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nexport { toBeEmptyElement } from './to-be-empty-element';\nexport { toBeExpanded } from './to-be-expanded';\nexport { toBeOnTheScreen } from './to-be-on-the-screen';\nexport { toBePartiallyChecked } from './to-be-partially-checked';\nexport { toBeSelected } from './to-be-selected';\nexport { toBeVisible } from './to-be-visible';\nexport { toContainElement } from './to-contain-element';\nexport { toHaveAccessibilityValue } from './to-have-accessibility-value';\nexport { toHaveAccessibleName } from './to-have-accessible-name';\nexport { toHaveDisplayValue } from './to-have-display-value';\nexport { toHaveProp } from './to-have-prop';\nexport { toHaveStyle } from './to-have-style';\nexport { toHaveTextContent } from './to-have-text-content';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,yBAAA,GAAAX,OAAA;AACA,IAAAY,qBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,WAAA,GAAAd,OAAA;AACA,IAAAe,YAAA,GAAAf,OAAA;AACA,IAAAgB,kBAAA,GAAAhB,OAAA"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ import { TextMatch, TextMatchOptions } from '../matches';
4
+ export declare function toHaveAccessibleName(this: jest.MatcherContext, element: ReactTestInstance, expectedName?: TextMatch, options?: TextMatchOptions): {
5
+ pass: boolean;
6
+ message: () => string;
7
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toHaveAccessibleName = toHaveAccessibleName;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _accessiblity = require("../helpers/accessiblity");
9
+ var _matches = require("../matches");
10
+ var _utils = require("./utils");
11
+ function toHaveAccessibleName(element, expectedName, options) {
12
+ (0, _utils.checkHostElement)(element, toHaveAccessibleName, this);
13
+ const receivedName = (0, _accessiblity.getAccessibleName)(element);
14
+ const missingExpectedValue = arguments.length === 1;
15
+ let pass = false;
16
+ if (missingExpectedValue) {
17
+ pass = receivedName !== '';
18
+ } else {
19
+ pass = expectedName != null ? (0, _matches.matches)(expectedName, receivedName, options?.normalizer, options?.exact) : false;
20
+ }
21
+ return {
22
+ pass,
23
+ message: () => {
24
+ return [(0, _utils.formatMessage)((0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveAccessibleName`, 'element', ''), `Expected element ${this.isNot ? 'not to' : 'to'} have accessible name`, expectedName, 'Received', receivedName)].join('\n');
25
+ }
26
+ };
27
+ }
28
+ //# sourceMappingURL=to-have-accessible-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-accessible-name.js","names":["_jestMatcherUtils","require","_accessiblity","_matches","_utils","toHaveAccessibleName","element","expectedName","options","checkHostElement","receivedName","getAccessibleName","missingExpectedValue","arguments","length","pass","matches","normalizer","exact","message","formatMessage","matcherHint","isNot","join"],"sources":["../../src/matchers/to-have-accessible-name.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport { getAccessibleName } from '../helpers/accessiblity';\nimport { TextMatch, TextMatchOptions, matches } from '../matches';\nimport { checkHostElement, formatMessage } from './utils';\n\nexport function toHaveAccessibleName(\n this: jest.MatcherContext,\n element: ReactTestInstance,\n expectedName?: TextMatch,\n options?: TextMatchOptions\n) {\n checkHostElement(element, toHaveAccessibleName, this);\n\n const receivedName = getAccessibleName(element);\n const missingExpectedValue = arguments.length === 1;\n\n let pass = false;\n if (missingExpectedValue) {\n pass = receivedName !== '';\n } else {\n pass =\n expectedName != null\n ? matches(\n expectedName,\n receivedName,\n options?.normalizer,\n options?.exact\n )\n : false;\n }\n\n return {\n pass,\n message: () => {\n return [\n formatMessage(\n matcherHint(\n `${this.isNot ? '.not' : ''}.toHaveAccessibleName`,\n 'element',\n ''\n ),\n `Expected element ${\n this.isNot ? 'not to' : 'to'\n } have accessible name`,\n expectedName,\n 'Received',\n receivedName\n ),\n ].join('\\n');\n },\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,SAASI,oBAAoBA,CAElCC,OAA0B,EAC1BC,YAAwB,EACxBC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACH,OAAO,EAAED,oBAAoB,EAAE,IAAI,CAAC;EAErD,MAAMK,YAAY,GAAG,IAAAC,+BAAiB,EAACL,OAAO,CAAC;EAC/C,MAAMM,oBAAoB,GAAGC,SAAS,CAACC,MAAM,KAAK,CAAC;EAEnD,IAAIC,IAAI,GAAG,KAAK;EAChB,IAAIH,oBAAoB,EAAE;IACxBG,IAAI,GAAGL,YAAY,KAAK,EAAE;EAC5B,CAAC,MAAM;IACLK,IAAI,GACFR,YAAY,IAAI,IAAI,GAChB,IAAAS,gBAAO,EACLT,YAAY,EACZG,YAAY,EACZF,OAAO,EAAES,UAAU,EACnBT,OAAO,EAAEU,KACX,CAAC,GACD,KAAK;EACb;EAEA,OAAO;IACLH,IAAI;IACJI,OAAO,EAAEA,CAAA,KAAM;MACb,OAAO,CACL,IAAAC,oBAAa,EACX,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACC,KAAK,GAAG,MAAM,GAAG,EAAG,uBAAsB,EAClD,SAAS,EACT,EACF,CAAC,EACA,oBACC,IAAI,CAACA,KAAK,GAAG,QAAQ,GAAG,IACzB,uBAAsB,EACvBf,YAAY,EACZ,UAAU,EACVG,YACF,CAAC,CACF,CAACa,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH"}
@@ -15,4 +15,4 @@ export declare function checkHostElement(element: ReactTestInstance | null | und
15
15
  */
16
16
  export declare function formatElement(element: ReactTestInstance | null): string;
17
17
  export declare function formatElementArray(elements: ReactTestInstance[]): string;
18
- export declare function formatMessage(matcher: string, expectedLabel: string, expectedValue: string | RegExp, receivedLabel: string, receivedValue: string | null | undefined): string;
18
+ export declare function formatMessage(matcher: string, expectedLabel: string, expectedValue: string | RegExp | null | undefined, receivedLabel: string, receivedValue: string | null | undefined): string;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["_jestMatcherUtils","require","_prettyFormat","_interopRequireWildcard","_redent","_interopRequireDefault","_componentTree","_formatDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","HostElementTypeError","Error","constructor","received","matcherFn","context","captureStackTrace","withType","printWithType","printReceived","message","matcherHint","isNot","name","RECEIVED_COLOR","join","checkHostElement","element","isHostElement","formatElement","children","props","childrenToDisplay","undefined","redent","prettyFormat","$$typeof","Symbol","for","type","defaultMapProps","plugins","ReactTestComponent","ReactElement","printFunctionName","printBasicPrototype","highlight","formatElementArray","elements","length","map","formatMessage","matcher","expectedLabel","expectedValue","receivedLabel","receivedValue","EXPECTED_COLOR","formatValue","value","stringify"],"sources":["../../src/matchers/utils.tsx"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n EXPECTED_COLOR,\n RECEIVED_COLOR,\n matcherHint,\n printWithType,\n printReceived,\n stringify,\n} from 'jest-matcher-utils';\nimport prettyFormat, { plugins } from 'pretty-format';\nimport redent from 'redent';\nimport { isHostElement } from '../helpers/component-tree';\nimport { defaultMapProps } from '../helpers/format-default';\n\nclass HostElementTypeError extends Error {\n constructor(\n received: unknown,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n ) {\n super();\n\n /* istanbul ignore next */\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, matcherFn);\n }\n\n let withType = '';\n try {\n withType = printWithType('Received', received, printReceived);\n /* istanbul ignore next */\n } catch (e) {\n // Deliberately empty.\n }\n\n this.message = [\n matcherHint(\n `${context.isNot ? '.not' : ''}.${matcherFn.name}`,\n 'received',\n ''\n ),\n '',\n `${RECEIVED_COLOR('received')} value must be a host element.`,\n withType,\n ].join('\\n');\n }\n}\n\n/**\n * Throws HostElementTypeError if passed element is not a host element.\n *\n * @param element ReactTestInstance to check.\n * @param matcherFn Matcher function calling the check used for formatting error.\n * @param context Jest matcher context used for formatting error.\n */\nexport function checkHostElement(\n element: ReactTestInstance | null | undefined,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n): asserts element is ReactTestInstance {\n if (!isHostElement(element)) {\n throw new HostElementTypeError(element, matcherFn, context);\n }\n}\n\n/***\n * Format given element as a pretty-printed string.\n *\n * @param element Element to format.\n */\nexport function formatElement(element: ReactTestInstance | null) {\n if (element == null) {\n return ' null';\n }\n\n const { children, ...props } = element.props;\n const childrenToDisplay =\n typeof children === 'string' ? [children] : undefined;\n\n return redent(\n prettyFormat(\n {\n // This prop is needed persuade the prettyFormat that the element is\n // a ReactTestRendererJSON instance, so it is formatted as JSX.\n $$typeof: Symbol.for('react.test.json'),\n type: element.type,\n props: defaultMapProps(props),\n children: childrenToDisplay,\n },\n {\n plugins: [plugins.ReactTestComponent, plugins.ReactElement],\n printFunctionName: false,\n printBasicPrototype: false,\n highlight: true,\n }\n ),\n 2\n );\n}\n\nexport function formatElementArray(elements: ReactTestInstance[]) {\n if (elements.length === 0) {\n return ' (no elements)';\n }\n\n return redent(elements.map(formatElement).join('\\n'), 2);\n}\n\nexport function formatMessage(\n matcher: string,\n expectedLabel: string,\n expectedValue: string | RegExp,\n receivedLabel: string,\n receivedValue: string | null | undefined\n) {\n return [\n `${matcher}\\n`,\n `${expectedLabel}:\\n${EXPECTED_COLOR(\n redent(formatValue(expectedValue), 2)\n )}`,\n `${receivedLabel}:\\n${RECEIVED_COLOR(\n redent(formatValue(receivedValue), 2)\n )}`,\n ].join('\\n');\n}\n\nfunction formatValue(value: unknown) {\n return typeof value === 'string' ? value : stringify(value);\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAQA,IAAAC,aAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AAA4D,SAAAI,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAA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C,MAAM,KAAK,CAAC,EAAE;IACzB,OAAO,iBAAiB;EAC1B;EAEA,OAAO,IAAAf,eAAM,EAACc,QAAQ,CAACE,GAAG,CAACrB,aAAa,CAAC,CAACJ,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1D;AAEO,SAAS0B,aAAaA,CAC3BC,OAAe,EACfC,aAAqB,EACrBC,aAA8B,EAC9BC,aAAqB,EACrBC,aAAwC,EACxC;EACA,OAAO,CACJ,GAAEJ,OAAQ,IAAG,EACb,GAAEC,aAAc,MAAK,IAAAI,gCAAc,EAClC,IAAAvB,eAAM,EAACwB,WAAW,CAACJ,aAAa,CAAC,EAAE,CAAC,CACtC,CAAE,EAAC,EACF,GAAEC,aAAc,MAAK,IAAA/B,gCAAc,EAClC,IAAAU,eAAM,EAACwB,WAAW,CAACF,aAAa,CAAC,EAAE,CAAC,CACtC,CAAE,EAAC,CACJ,CAAC/B,IAAI,CAAC,IAAI,CAAC;AACd;AAEA,SAASiC,WAAWA,CAACC,KAAc,EAAE;EACnC,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,IAAAC,2BAAS,EAACD,KAAK,CAAC;AAC7D"}
1
+ {"version":3,"file":"utils.js","names":["_jestMatcherUtils","require","_prettyFormat","_interopRequireWildcard","_redent","_interopRequireDefault","_componentTree","_formatDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","HostElementTypeError","Error","constructor","received","matcherFn","context","captureStackTrace","withType","printWithType","printReceived","message","matcherHint","isNot","name","RECEIVED_COLOR","join","checkHostElement","element","isHostElement","formatElement","children","props","childrenToDisplay","undefined","redent","prettyFormat","$$typeof","Symbol","for","type","defaultMapProps","plugins","ReactTestComponent","ReactElement","printFunctionName","printBasicPrototype","highlight","formatElementArray","elements","length","map","formatMessage","matcher","expectedLabel","expectedValue","receivedLabel","receivedValue","EXPECTED_COLOR","formatValue","value","stringify"],"sources":["../../src/matchers/utils.tsx"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n EXPECTED_COLOR,\n RECEIVED_COLOR,\n matcherHint,\n printWithType,\n printReceived,\n stringify,\n} from 'jest-matcher-utils';\nimport prettyFormat, { plugins } from 'pretty-format';\nimport redent from 'redent';\nimport { isHostElement } from '../helpers/component-tree';\nimport { defaultMapProps } from '../helpers/format-default';\n\nclass HostElementTypeError extends Error {\n constructor(\n received: unknown,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n ) {\n super();\n\n /* istanbul ignore next */\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, matcherFn);\n }\n\n let withType = '';\n try {\n withType = printWithType('Received', received, printReceived);\n /* istanbul ignore next */\n } catch (e) {\n // Deliberately empty.\n }\n\n this.message = [\n matcherHint(\n `${context.isNot ? '.not' : ''}.${matcherFn.name}`,\n 'received',\n ''\n ),\n '',\n `${RECEIVED_COLOR('received')} value must be a host element.`,\n withType,\n ].join('\\n');\n }\n}\n\n/**\n * Throws HostElementTypeError if passed element is not a host element.\n *\n * @param element ReactTestInstance to check.\n * @param matcherFn Matcher function calling the check used for formatting error.\n * @param context Jest matcher context used for formatting error.\n */\nexport function checkHostElement(\n element: ReactTestInstance | null | undefined,\n matcherFn: jest.CustomMatcher,\n context: jest.MatcherContext\n): asserts element is ReactTestInstance {\n if (!isHostElement(element)) {\n throw new HostElementTypeError(element, matcherFn, context);\n }\n}\n\n/***\n * Format given element as a pretty-printed string.\n *\n * @param element Element to format.\n */\nexport function formatElement(element: ReactTestInstance | null) {\n if (element == null) {\n return ' null';\n }\n\n const { children, ...props } = element.props;\n const childrenToDisplay =\n typeof children === 'string' ? [children] : undefined;\n\n return redent(\n prettyFormat(\n {\n // This prop is needed persuade the prettyFormat that the element is\n // a ReactTestRendererJSON instance, so it is formatted as JSX.\n $$typeof: Symbol.for('react.test.json'),\n type: element.type,\n props: defaultMapProps(props),\n children: childrenToDisplay,\n },\n {\n plugins: [plugins.ReactTestComponent, plugins.ReactElement],\n printFunctionName: false,\n printBasicPrototype: false,\n highlight: true,\n }\n ),\n 2\n );\n}\n\nexport function formatElementArray(elements: ReactTestInstance[]) {\n if (elements.length === 0) {\n return ' (no elements)';\n }\n\n return redent(elements.map(formatElement).join('\\n'), 2);\n}\n\nexport function formatMessage(\n matcher: string,\n expectedLabel: string,\n expectedValue: string | RegExp | null | undefined,\n receivedLabel: string,\n receivedValue: string | null | undefined\n) {\n return [\n `${matcher}\\n`,\n `${expectedLabel}:\\n${EXPECTED_COLOR(\n redent(formatValue(expectedValue), 2)\n )}`,\n `${receivedLabel}:\\n${RECEIVED_COLOR(\n redent(formatValue(receivedValue), 2)\n )}`,\n ].join('\\n');\n}\n\nfunction formatValue(value: unknown) {\n return typeof value === 'string' ? value : stringify(value);\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAQA,IAAAC,aAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AAA4D,SAAAI,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GA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,EAAE;EAChE,IAAIA,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAE;IACzB,OAAO,iBAAiB;EAC1B;EAEA,OAAO,IAAAf,eAAM,EAACc,QAAQ,CAACE,GAAG,CAACrB,aAAa,CAAC,CAACJ,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1D;AAEO,SAAS0B,aAAaA,CAC3BC,OAAe,EACfC,aAAqB,EACrBC,aAAiD,EACjDC,aAAqB,EACrBC,aAAwC,EACxC;EACA,OAAO,CACJ,GAAEJ,OAAQ,IAAG,EACb,GAAEC,aAAc,MAAK,IAAAI,gCAAc,EAClC,IAAAvB,eAAM,EAACwB,WAAW,CAACJ,aAAa,CAAC,EAAE,CAAC,CACtC,CAAE,EAAC,EACF,GAAEC,aAAc,MAAK,IAAA/B,gCAAc,EAClC,IAAAU,eAAM,EAACwB,WAAW,CAACF,aAAa,CAAC,EAAE,CAAC,CACtC,CAAE,EAAC,CACJ,CAAC/B,IAAI,CAAC,IAAI,CAAC;AACd;AAEA,SAASiC,WAAWA,CAACC,KAAc,EAAE;EACnC,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,IAAAC,2BAAS,EAACD,KAAK,CAAC;AAC7D"}
@@ -8,7 +8,9 @@ var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  function renderWithAct(component, options) {
10
10
  let renderer;
11
- _reactTestRenderer.default.act(() => {
11
+
12
+ // This will be called synchronously.
13
+ void _reactTestRenderer.default.act(() => {
12
14
  renderer = _reactTestRenderer.default.create(component, options);
13
15
  });
14
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"render-act.js","names":["_reactTestRenderer","_interopRequireDefault","require","obj","__esModule","default","renderWithAct","component","options","renderer","TestRenderer","act","create"],"sources":["../src/render-act.ts"],"sourcesContent":["import TestRenderer from 'react-test-renderer';\nimport type {\n ReactTestRenderer,\n TestRendererOptions,\n} from 'react-test-renderer';\n\nexport function renderWithAct(\n component: React.ReactElement,\n options?: TestRendererOptions\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n TestRenderer.act(() => {\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-ignore act is synchronous, so renderer is already initialised here\n return renderer;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAMxC,SAASG,aAAaA,CAC3BC,SAA6B,EAC7BC,OAA6B,EACV;EACnB,IAAIC,QAA2B;EAE/BC,0BAAY,CAACC,GAAG,CAAC,MAAM;IACrBF,QAAQ,GAAGC,0BAAY,CAACE,MAAM,CAACL,SAAS,EAAEC,OAAO,CAAC;EACpD,CAAC,CAAC;;EAEF;EACA,OAAOC,QAAQ;AACjB"}
1
+ {"version":3,"file":"render-act.js","names":["_reactTestRenderer","_interopRequireDefault","require","obj","__esModule","default","renderWithAct","component","options","renderer","TestRenderer","act","create"],"sources":["../src/render-act.ts"],"sourcesContent":["import TestRenderer from 'react-test-renderer';\nimport type {\n ReactTestRenderer,\n TestRendererOptions,\n} from 'react-test-renderer';\n\nexport function renderWithAct(\n component: React.ReactElement,\n options?: TestRendererOptions\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n // This will be called synchronously.\n void TestRenderer.act(() => {\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-ignore act is synchronous, so renderer is already initialised here\n return renderer;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAMxC,SAASG,aAAaA,CAC3BC,SAA6B,EAC7BC,OAA6B,EACV;EACnB,IAAIC,QAA2B;;EAE/B;EACA,KAAKC,0BAAY,CAACC,GAAG,CAAC,MAAM;IAC1BF,QAAQ,GAAGC,0BAAY,CAACE,MAAM,CAACL,SAAS,EAAEC,OAAO,CAAC;EACpD,CAAC,CAAC;;EAEF;EACA,OAAOC,QAAQ;AACjB"}
package/build/render.js CHANGED
@@ -72,7 +72,7 @@ function buildRenderResult(renderer, wrap) {
72
72
  const update = updateWithAct(renderer, wrap);
73
73
  const instance = renderer.root;
74
74
  const unmount = () => {
75
- (0, _act.default)(() => {
75
+ void (0, _act.default)(() => {
76
76
  renderer.unmount();
77
77
  });
78
78
  };
@@ -104,7 +104,7 @@ function buildRenderResult(renderer, wrap) {
104
104
  }
105
105
  function updateWithAct(renderer, wrap) {
106
106
  return function (component) {
107
- (0, _act.default)(() => {
107
+ void (0, _act.default)(() => {
108
108
  renderer.update(wrap(component));
109
109
  });
110
110
  };
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","names":["_react","_interopRequireWildcard","require","React","_act","_interopRequireDefault","_cleanup","_config","_componentTree","_debugDeep","_debugShallow","_hostComponentNames","_stringValidation","_renderAct","_screen","_within","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","render","component","options","renderInternal","wrapper","Wrapper","createNodeMock","unstable_validateStringsRenderedWithinText","detectHostComponentNames","configureHostComponentNamesIfNeeded","renderWithStringValidation","wrap","element","createElement","renderer","renderWithAct","undefined","buildRenderResult","handleRender","_","phase","validateStringsRenderedWithinText","screen","toJSON","Profiler","id","onRender","update","updateWithAct","instance","root","unmount","act","addToCleanupQueue","result","getQueriesForElement","rerender","debug","getHostChildren","UNSAFE_root","enumerable","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","message","console","warn","json","debugDeep","shallow","debugShallow"],"sources":["../src/render.tsx"],"sourcesContent":["import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport { Profiler } from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport { getHostChildren } from './helpers/component-tree';\nimport debugDeep, { DebugOptions } from './helpers/debug-deep';\nimport debugShallow from './helpers/debug-shallow';\nimport { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';\nimport { validateStringsRenderedWithinText } from './helpers/string-validation';\nimport { renderWithAct } from './render-act';\nimport { setRenderResult, screen } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => any;\n unstable_validateStringsRenderedWithinText?: boolean;\n}\n\nexport type RenderResult = ReturnType<typeof render>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(\n component: React.ReactElement<T>,\n options: RenderOptions = {}\n) {\n return renderInternal(component, options);\n}\n\nexport interface RenderInternalOptions extends RenderOptions {\n detectHostComponentNames?: boolean;\n}\n\nexport function renderInternal<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n unstable_validateStringsRenderedWithinText,\n detectHostComponentNames = true,\n }: RenderInternalOptions = {}\n) {\n if (detectHostComponentNames) {\n configureHostComponentNamesIfNeeded();\n }\n\n if (unstable_validateStringsRenderedWithinText) {\n return renderWithStringValidation(component, {\n wrapper: Wrapper,\n createNodeMock,\n });\n }\n\n const wrap = (element: React.ReactElement) =>\n Wrapper ? <Wrapper>{element}</Wrapper> : element;\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction renderWithStringValidation<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n }: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {}\n) {\n const handleRender: React.ProfilerProps['onRender'] = (_, phase) => {\n if (phase === 'update') {\n validateStringsRenderedWithinText(screen.toJSON());\n }\n };\n\n const wrap = (element: React.ReactElement) => (\n <Profiler id=\"renderProfiler\" onRender={handleRender}>\n {Wrapper ? <Wrapper>{element}</Wrapper> : element}\n </Profiler>\n );\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n validateStringsRenderedWithinText(renderer.toJSON());\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => JSX.Element\n) {\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n\n const unmount = () => {\n act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(instance),\n update,\n unmount,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n get root(): ReactTestInstance {\n return getHostChildren(instance)[0];\n },\n UNSAFE_root: instance,\n };\n\n // Add as non-enumerable property, so that it's safe to enumerate\n // `render` result, e.g. using destructuring rest syntax.\n Object.defineProperty(result, 'container', {\n enumerable: false,\n get() {\n throw new Error(\n \"'container' property has been renamed to 'UNSAFE_root'.\\n\\n\" +\n \"Consider using 'root' property which returns root host element.\"\n );\n },\n });\n\n setRenderResult(result);\n return result;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement\n) {\n return function (component: React.ReactElement) {\n act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\nexport interface DebugFunction {\n (options?: DebugOptions | string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(\n instance: ReactTestInstance,\n renderer: ReactTestRenderer\n): DebugFunction {\n function debugImpl(options?: DebugOptions | string) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions =\n typeof options === 'string'\n ? { ...defaultDebugOptions, message: options }\n : { ...defaultDebugOptions, ...options };\n\n if (typeof options === 'string') {\n // eslint-disable-next-line no-console\n console.warn(\n 'Using debug(\"message\") is deprecated and will be removed in future release, please use debug({ message; \"message\" }) instead.'\n );\n }\n\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, debugOptions);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,IAAAC,KAAA,GAAAH,MAAA;AAE/B,IAAAI,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,aAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,UAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AAAgD,SAAAG,uBAAAW,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAnB,wBAAAmB,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CA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AAmB;MAAEG,OAAO,EAAE7C;IAAQ,CAAC,GAC5C;MAAE,GAAG0C,mBAAmB;MAAE,GAAG1C;IAAQ,CAAC;IAE5C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/B;MACA8C,OAAO,CAACC,IAAI,CACV,+HACF,CAAC;IACH;IAEA,MAAMC,IAAI,GAAGpC,QAAQ,CAACS,MAAM,CAAC,CAAC;IAC9B,IAAI2B,IAAI,EAAE;MACR,OAAO,IAAAC,kBAAS,EAACD,IAAI,EAAEJ,YAAY,CAAC;IACtC;EACF;EACAH,SAAS,CAACS,OAAO,GAAIL,OAAgB,IAAK,IAAAM,qBAAY,EAACxB,QAAQ,EAAEkB,OAAO,CAAC;EACzE,OAAOJ,SAAS;AAClB"}
1
+ {"version":3,"file":"render.js","names":["_react","_interopRequireWildcard","require","React","_act","_interopRequireDefault","_cleanup","_config","_componentTree","_debugDeep","_debugShallow","_hostComponentNames","_stringValidation","_renderAct","_screen","_within","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","render","component","options","renderInternal","wrapper","Wrapper","createNodeMock","unstable_validateStringsRenderedWithinText","detectHostComponentNames","configureHostComponentNamesIfNeeded","renderWithStringValidation","wrap","element","createElement","renderer","renderWithAct","undefined","buildRenderResult","handleRender","_","phase","validateStringsRenderedWithinText","screen","toJSON","Profiler","id","onRender","update","updateWithAct","instance","root","unmount","act","addToCleanupQueue","result","getQueriesForElement","rerender","debug","getHostChildren","UNSAFE_root","enumerable","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","message","console","warn","json","debugDeep","shallow","debugShallow"],"sources":["../src/render.tsx"],"sourcesContent":["import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport { Profiler } from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport { getHostChildren } from './helpers/component-tree';\nimport debugDeep, { DebugOptions } from './helpers/debug-deep';\nimport debugShallow from './helpers/debug-shallow';\nimport { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';\nimport { validateStringsRenderedWithinText } from './helpers/string-validation';\nimport { renderWithAct } from './render-act';\nimport { setRenderResult, screen } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => any;\n unstable_validateStringsRenderedWithinText?: boolean;\n}\n\nexport type RenderResult = ReturnType<typeof render>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(\n component: React.ReactElement<T>,\n options: RenderOptions = {}\n) {\n return renderInternal(component, options);\n}\n\nexport interface RenderInternalOptions extends RenderOptions {\n detectHostComponentNames?: boolean;\n}\n\nexport function renderInternal<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n unstable_validateStringsRenderedWithinText,\n detectHostComponentNames = true,\n }: RenderInternalOptions = {}\n) {\n if (detectHostComponentNames) {\n configureHostComponentNamesIfNeeded();\n }\n\n if (unstable_validateStringsRenderedWithinText) {\n return renderWithStringValidation(component, {\n wrapper: Wrapper,\n createNodeMock,\n });\n }\n\n const wrap = (element: React.ReactElement) =>\n Wrapper ? <Wrapper>{element}</Wrapper> : element;\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction renderWithStringValidation<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n }: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {}\n) {\n const handleRender: React.ProfilerProps['onRender'] = (_, phase) => {\n if (phase === 'update') {\n validateStringsRenderedWithinText(screen.toJSON());\n }\n };\n\n const wrap = (element: React.ReactElement) => (\n <Profiler id=\"renderProfiler\" onRender={handleRender}>\n {Wrapper ? <Wrapper>{element}</Wrapper> : element}\n </Profiler>\n );\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n validateStringsRenderedWithinText(renderer.toJSON());\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => JSX.Element\n) {\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(instance),\n update,\n unmount,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n get root(): ReactTestInstance {\n return getHostChildren(instance)[0];\n },\n UNSAFE_root: instance,\n };\n\n // Add as non-enumerable property, so that it's safe to enumerate\n // `render` result, e.g. using destructuring rest syntax.\n Object.defineProperty(result, 'container', {\n enumerable: false,\n get() {\n throw new Error(\n \"'container' property has been renamed to 'UNSAFE_root'.\\n\\n\" +\n \"Consider using 'root' property which returns root host element.\"\n );\n },\n });\n\n setRenderResult(result);\n return result;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement\n) {\n return function (component: React.ReactElement) {\n void act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\nexport interface DebugFunction {\n (options?: DebugOptions | string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(\n instance: ReactTestInstance,\n renderer: ReactTestRenderer\n): DebugFunction {\n function debugImpl(options?: DebugOptions | string) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions =\n typeof options === 'string'\n ? { ...defaultDebugOptions, message: options }\n : { ...defaultDebugOptions, ...options };\n\n if (typeof options === 'string') {\n // eslint-disable-next-line no-console\n console.warn(\n 'Using debug(\"message\") is deprecated and will be removed in future release, please use debug({ message; \"message\" }) instead.'\n );\n }\n\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json,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AAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/B;MACA8C,OAAO,CAACC,IAAI,CACV,+HACF,CAAC;IACH;IAEA,MAAMC,IAAI,GAAGpC,QAAQ,CAACS,MAAM,CAAC,CAAC;IAC9B,IAAI2B,IAAI,EAAE;MACR,OAAO,IAAAC,kBAAS,EAACD,IAAI,EAAEJ,YAAY,CAAC;IACtC;EACF;EACAH,SAAS,CAACS,OAAO,GAAIL,OAAgB,IAAK,IAAAM,qBAAY,EAACxB,QAAQ,EAAEkB,OAAO,CAAC;EACzE,OAAOJ,SAAS;AAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","names":["_timers","require","_wrapAsync","_clear","_press","_scroll","_type","_utils","universalJestAdvanceTimersBy","ms","jestFakeTimersAreEnabled","jest","advanceTimersByTime","Promise","resolve","defaultOptions","delay","advanceTimers","setup","options","config","createConfig","instance","createInstance","api","press","wrapAndBindImpl","longPress","type","clear","scrollTo","Object","assign","impl","method","args","wrapAsync","apply","then","result","wait","defineProperty","get","name"],"sources":["../../../src/user-event/setup/setup.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { jestFakeTimersAreEnabled } from '../../helpers/timers';\nimport { wrapAsync } from '../../helpers/wrap-async';\nimport { clear } from '../clear';\nimport { PressOptions, press, longPress } from '../press';\nimport { ScrollToOptions, scrollTo } from '../scroll';\nimport { TypeOptions, type } from '../type';\nimport { wait } from '../utils';\n\nexport interface UserEventSetupOptions {\n /**\n * Between some subsequent inputs like typing a series of characters\n * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.\n * This moves the next changes at least to next macro task\n * and allows other (asynchronous) code to run between events.\n *\n * `null` prevents `setTimeout` from being called.\n *\n * @default 0\n */\n delay?: number;\n\n /**\n * Function to be called to advance fake timers. Setting it is necessary for\n * fake timers to work.\n *\n * @example jest.advanceTimersByTime\n */\n advanceTimers?: (delay: number) => Promise<void> | void;\n}\n\n/**\n * This functions allow wait to work correctly under both real and fake Jest timers.\n */\nfunction universalJestAdvanceTimersBy(ms: number) {\n if (jestFakeTimersAreEnabled()) {\n return jest.advanceTimersByTime(ms);\n } else {\n return Promise.resolve();\n }\n}\n\nconst defaultOptions: Required<UserEventSetupOptions> = {\n delay: 0,\n advanceTimers: universalJestAdvanceTimersBy,\n};\n\n/**\n * Creates a new instance of user event instance with the given options.\n *\n * @param options\n * @returns UserEvent instance\n */\nexport function setup(options?: UserEventSetupOptions) {\n const config = createConfig(options);\n const instance = createInstance(config);\n return instance;\n}\n\n/**\n * Options affecting all user event interactions.\n *\n * @param delay between some subsequent inputs like typing a series of characters\n * @param advanceTimers function to be called to advance fake timers\n */\nexport interface UserEventConfig {\n delay: number;\n advanceTimers: (delay: number) => Promise<void> | void;\n}\n\nfunction createConfig(options?: UserEventSetupOptions): UserEventConfig {\n return {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * UserEvent instance used to invoke user interaction functions.\n */\nexport interface UserEventInstance {\n config: UserEventConfig;\n\n press: (element: ReactTestInstance) => Promise<void>;\n longPress: (\n element: ReactTestInstance,\n options?: PressOptions\n ) => Promise<void>;\n\n /**\n * Simulate user pressing on a given `TextInput` element and typing given text.\n *\n * This method will trigger the events for each character of the text:\n * `keyPress`, `change`, `changeText`, `endEditing`, etc.\n *\n * It will also trigger events connected with entering and leaving the text\n * input.\n *\n * The exact events sent depend on the props of the TextInput (`editable`,\n * `multiline`, value, defaultValue, etc) and passed options.\n *\n * @param element TextInput element to type on\n * @param text Text to type\n * @param options Options affecting typing behavior:\n * - `skipPress` - if true, `pressIn` and `pressOut` events will not be\n * triggered.\n * - `submitEditing` - if true, `submitEditing` event will be triggered after\n * typing the text.\n */\n type: (\n element: ReactTestInstance,\n text: string,\n options?: TypeOptions\n ) => Promise<void>;\n\n /**\n * Simulate user clearing the text of a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. pressing backspace to delete all text\n * 4. leaving TextInput\n *\n * @param element TextInput element to clear\n */\n clear: (element: ReactTestInstance) => Promise<void>;\n\n /**\n * Simlate user scorlling a ScrollView element.\n *\n * @param element ScrollView element\n * @returns\n */\n scrollTo: (\n element: ReactTestInstance,\n options: ScrollToOptions\n ) => Promise<void>;\n}\n\nfunction createInstance(config: UserEventConfig): UserEventInstance {\n const instance = {\n config,\n } as UserEventInstance;\n\n // Bind interactions to given User Event instance.\n const api = {\n press: wrapAndBindImpl(instance, press),\n longPress: wrapAndBindImpl(instance, longPress),\n type: wrapAndBindImpl(instance, type),\n clear: wrapAndBindImpl(instance, clear),\n scrollTo: wrapAndBindImpl(instance, scrollTo),\n };\n\n Object.assign(instance, api);\n return instance;\n}\n\n/**\n * Wraps user interaction with `wrapAsync` (temporarily disable `act` environment while\n * calling & resolving the async callback, then flush the microtask queue)\n *\n * This implementation is sourced from `testing-library/user-event`\n * @see https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/setup/setup.ts#L121\n */\nfunction wrapAndBindImpl<\n Args extends any[],\n Impl extends (this: UserEventInstance, ...args: Args) => Promise<unknown>\n>(instance: UserEventInstance, impl: Impl) {\n function method(...args: Args) {\n return wrapAsync(() =>\n // eslint-disable-next-line promise/prefer-await-to-then\n impl.apply(instance, args).then(async (result) => {\n await wait(instance.config);\n return result;\n })\n );\n }\n\n // Copy implementation name to the returned function\n Object.defineProperty(method, 'name', { get: () => impl.name });\n\n return method as Impl;\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAwBA;AACA;AACA;AACA,SAASO,4BAA4BA,CAACC,EAAU,EAAE;EAChD,IAAI,IAAAC,gCAAwB,EAAC,CAAC,EAAE;IAC9B,OA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;IACAH,IAAI,CAACI,KAAK,CAACf,QAAQ,EAAEa,IAAI,CAAC,CAACG,IAAI,CAAC,MAAOC,MAAM,IAAK;MAChD,MAAM,IAAAC,WAAI,EAAClB,QAAQ,CAACF,MAAM,CAAC;MAC3B,OAAOmB,MAAM;IACf,CAAC,CACH,CAAC;EACH;;EAEA;EACAR,MAAM,CAACU,cAAc,CAACP,MAAM,EAAE,MAAM,EAAE;IAAEQ,GAAG,EAAEA,CAAA,KAAMT,IAAI,CAACU;EAAK,CAAC,CAAC;EAE/D,OAAOT,MAAM;AACf"}
1
+ {"version":3,"file":"setup.js","names":["_timers","require","_wrapAsync","_clear","_press","_scroll","_type","_utils","universalJestAdvanceTimersBy","ms","jestFakeTimersAreEnabled","jest","advanceTimersByTime","Promise","resolve","defaultOptions","delay","advanceTimers","setup","options","config","createConfig","instance","createInstance","api","press","wrapAndBindImpl","longPress","type","clear","scrollTo","Object","assign","impl","method","args","wrapAsync","apply","then","result","wait","defineProperty","get","name"],"sources":["../../../src/user-event/setup/setup.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { jestFakeTimersAreEnabled } from '../../helpers/timers';\nimport { wrapAsync } from '../../helpers/wrap-async';\nimport { clear } from '../clear';\nimport { PressOptions, press, longPress } from '../press';\nimport { ScrollToOptions, scrollTo } from '../scroll';\nimport { TypeOptions, type } from '../type';\nimport { wait } from '../utils';\n\nexport interface UserEventSetupOptions {\n /**\n * Between some subsequent inputs like typing a series of characters\n * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.\n * This moves the next changes at least to next macro task\n * and allows other (asynchronous) code to run between events.\n *\n * `null` prevents `setTimeout` from being called.\n *\n * @default 0\n */\n delay?: number;\n\n /**\n * Function to be called to advance fake timers. Setting it is necessary for\n * fake timers to work.\n *\n * @example jest.advanceTimersByTime\n */\n advanceTimers?: (delay: number) => Promise<void> | void;\n}\n\n/**\n * This functions allow wait to work correctly under both real and fake Jest timers.\n */\nfunction universalJestAdvanceTimersBy(ms: number) {\n if (jestFakeTimersAreEnabled()) {\n return jest.advanceTimersByTime(ms);\n } else {\n return Promise.resolve();\n }\n}\n\nconst defaultOptions: Required<UserEventSetupOptions> = {\n delay: 0,\n advanceTimers: universalJestAdvanceTimersBy,\n};\n\n/**\n * Creates a new instance of user event instance with the given options.\n *\n * @param options\n * @returns UserEvent instance\n */\nexport function setup(options?: UserEventSetupOptions) {\n const config = createConfig(options);\n const instance = createInstance(config);\n return instance;\n}\n\n/**\n * Options affecting all user event interactions.\n *\n * @param delay between some subsequent inputs like typing a series of characters\n * @param advanceTimers function to be called to advance fake timers\n */\nexport interface UserEventConfig {\n delay: number;\n advanceTimers: (delay: number) => Promise<void> | void;\n}\n\nfunction createConfig(options?: UserEventSetupOptions): UserEventConfig {\n return {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * UserEvent instance used to invoke user interaction functions.\n */\nexport interface UserEventInstance {\n config: UserEventConfig;\n\n press: (element: ReactTestInstance) => Promise<void>;\n longPress: (\n element: ReactTestInstance,\n options?: PressOptions\n ) => Promise<void>;\n\n /**\n * Simulate user pressing on a given `TextInput` element and typing given text.\n *\n * This method will trigger the events for each character of the text:\n * `keyPress`, `change`, `changeText`, `endEditing`, etc.\n *\n * It will also trigger events connected with entering and leaving the text\n * input.\n *\n * The exact events sent depend on the props of the TextInput (`editable`,\n * `multiline`, value, defaultValue, etc) and passed options.\n *\n * @param element TextInput element to type on\n * @param text Text to type\n * @param options Options affecting typing behavior:\n * - `skipPress` - if true, `pressIn` and `pressOut` events will not be\n * triggered.\n * - `submitEditing` - if true, `submitEditing` event will be triggered after\n * typing the text.\n */\n type: (\n element: ReactTestInstance,\n text: string,\n options?: TypeOptions\n ) => Promise<void>;\n\n /**\n * Simulate user clearing the text of a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. pressing backspace to delete all text\n * 4. leaving TextInput\n *\n * @param element TextInput element to clear\n */\n clear: (element: ReactTestInstance) => Promise<void>;\n\n /**\n * Simlate user scorlling a ScrollView element.\n *\n * @param element ScrollView element\n * @returns\n */\n scrollTo: (\n element: ReactTestInstance,\n options: ScrollToOptions\n ) => Promise<void>;\n}\n\nfunction createInstance(config: UserEventConfig): UserEventInstance {\n const instance = {\n config,\n } as UserEventInstance;\n\n // Bind interactions to given User Event instance.\n const api = {\n press: wrapAndBindImpl(instance, press),\n longPress: wrapAndBindImpl(instance, longPress),\n type: wrapAndBindImpl(instance, type),\n clear: wrapAndBindImpl(instance, clear),\n scrollTo: wrapAndBindImpl(instance, scrollTo),\n };\n\n Object.assign(instance, api);\n return instance;\n}\n\n/**\n * Wraps user interaction with `wrapAsync` (temporarily disable `act` environment while\n * calling & resolving the async callback, then flush the microtask queue)\n *\n * This implementation is sourced from `testing-library/user-event`\n * @see https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/setup/setup.ts#L121\n */\nfunction wrapAndBindImpl<\n Args extends any[],\n Impl extends (this: UserEventInstance, ...args: Args) => Promise<unknown>,\n>(instance: UserEventInstance, impl: Impl) {\n function method(...args: Args) {\n return wrapAsync(() =>\n // eslint-disable-next-line promise/prefer-await-to-then\n impl.apply(instance, args).then(async (result) => {\n await wait(instance.config);\n return result;\n })\n );\n }\n\n // Copy implementation name to the returned function\n Object.defineProperty(method, 'name', { get: () => impl.name });\n\n return method as Impl;\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAwBA;AACA;AACA;AACA,SAASO,4BAA4BA,CAACC,EAAU,EAAE;EAChD,IAAI,IAAAC,gCAAwB,EAAC,CAAC,EAAE;IAC9B,OAAOC,IAAI,CAACC,mBAAmB,C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AACf,QAAQ,EAAEa,IAAI,CAAC,CAACG,IAAI,CAAC,MAAOC,MAAM,IAAK;MAChD,MAAM,IAAAC,WAAI,EAAClB,QAAQ,CAACF,MAAM,CAAC;MAC3B,OAAOmB,MAAM;IACf,CAAC,CACH,CAAC;EACH;;EAEA;EACAR,MAAM,CAACU,cAAc,CAACP,MAAM,EAAE,MAAM,EAAE;IAAEQ,GAAG,EAAEA,CAAA,KAAMT,IAAI,CAACU;EAAK,CAAC,CAAC;EAE/D,OAAOT,MAAM;AACf"}
@@ -18,7 +18,9 @@ function dispatchEvent(element, eventName, event) {
18
18
  if (!handler) {
19
19
  return;
20
20
  }
21
- (0, _act.default)(() => {
21
+
22
+ // This will be called synchronously.
23
+ void (0, _act.default)(() => {
22
24
  handler(event);
23
25
  });
24
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\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\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n event: unknown\n) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n act(() => {\n handler(event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,EACjBC,KAAc,EACd;EACA,MAAMC,OAAO,GAAGC,eAAe,CAACJ,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACE,OAAO,EAAE;IACZ;EACF;EAEA,IAAAE,YAAG,EAAC,MAAM;IACRF,OAAO,CAACD,KAAK,CAAC;EAChB,CAAC,CAAC;AACJ;AAEA,SAASE,eAAeA,CAACJ,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMK,UAAU,GAAGC,mBAAmB,CAACN,SAAS,CAAC;EACjD,MAAMO,MAAM,GAAGR,OAAO,CAACS,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACN,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACU,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEX,SAAS,CAACY,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE"}
1
+ {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\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\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n event: unknown\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\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,EACjBC,KAAc,EACd;EACA,MAAMC,OAAO,GAAGC,eAAe,CAACJ,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACE,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAACD,KAAK,CAAC;EAChB,CAAC,CAAC;AACJ;AAEA,SAASE,eAAeA,CAACJ,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMK,UAAU,GAAGC,mBAAmB,CAACN,SAAS,CAAC;EACjD,MAAMO,MAAM,GAAGR,OAAO,CAACS,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACN,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACU,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEX,SAAS,CAACY,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE"}
@@ -19,7 +19,7 @@ async function waitForElementToBeRemoved(expectation, options) {
19
19
  if (isRemoved(initialElements)) {
20
20
  throw new _errors.ErrorWithStack('The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.', waitForElementToBeRemoved);
21
21
  }
22
- return (0, _waitFor.default)(() => {
22
+ return await (0, _waitFor.default)(() => {
23
23
  let result;
24
24
  try {
25
25
  result = expectation();
@@ -1 +1 @@
1
- {"version":3,"file":"wait-for-element-to-be-removed.js","names":["_waitFor","_interopRequireDefault","require","_errors","obj","__esModule","default","isRemoved","result","Array","isArray","length","waitForElementToBeRemoved","expectation","options","timeoutError","ErrorWithStack","initialElements","waitFor","error"],"sources":["../src/wait-for-element-to-be-removed.ts"],"sourcesContent":["import waitFor from './wait-for';\nimport type { WaitForOptions } from './wait-for';\nimport { ErrorWithStack } from './helpers/errors';\n\nfunction isRemoved<T>(result: T): boolean {\n return !result || (Array.isArray(result) && !result.length);\n}\n\nexport default async function waitForElementToBeRemoved<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Created here so we get a nice stacktrace\n const timeoutError = new ErrorWithStack(\n 'Timed out in waitForElementToBeRemoved.',\n waitForElementToBeRemoved\n );\n\n // Elements have to be present initally and then removed.\n const initialElements = expectation();\n if (isRemoved(initialElements)) {\n throw new ErrorWithStack(\n 'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',\n waitForElementToBeRemoved\n );\n }\n\n return waitFor(() => {\n let result;\n try {\n result = expectation();\n } catch (error) {\n return initialElements;\n }\n\n if (!isRemoved(result)) {\n throw timeoutError;\n }\n\n return initialElements;\n }, options);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,SAASG,SAASA,CAAIC,MAAS,EAAW;EACxC,OAAO,CAACA,MAAM,IAAKC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,IAAI,CAACA,MAAM,CAACG,MAAO;AAC7D;AAEe,eAAeC,yBAAyBA,CACrDC,WAAoB,EACpBC,OAAwB,EACZ;EACZ;EACA,MAAMC,YAAY,GAAG,IAAIC,sBAAc,CACrC,yCAAyC,EACzCJ,yBACF,CAAC;;EAED;EACA,MAAMK,eAAe,GAAGJ,WAAW,CAAC,CAAC;EACrC,IAAIN,SAAS,CAACU,eAAe,CAAC,EAAE;IAC9B,MAAM,IAAID,sBAAc,CACtB,oKAAoK,EACpKJ,yBACF,CAAC;EACH;EAEA,OAAO,IAAAM,gBAAO,EAAC,MAAM;IACnB,IAAIV,MAAM;IACV,IAAI;MACFA,MAAM,GAAGK,WAAW,CAAC,CAAC;IACxB,CAAC,CAAC,OAAOM,KAAK,EAAE;MACd,OAAOF,eAAe;IACxB;IAEA,IAAI,CAACV,SAAS,CAACC,MAAM,CAAC,EAAE;MACtB,MAAMO,YAAY;IACpB;IAEA,OAAOE,eAAe;EACxB,CAAC,EAAEH,OAAO,CAAC;AACb"}
1
+ {"version":3,"file":"wait-for-element-to-be-removed.js","names":["_waitFor","_interopRequireDefault","require","_errors","obj","__esModule","default","isRemoved","result","Array","isArray","length","waitForElementToBeRemoved","expectation","options","timeoutError","ErrorWithStack","initialElements","waitFor","error"],"sources":["../src/wait-for-element-to-be-removed.ts"],"sourcesContent":["import waitFor from './wait-for';\nimport type { WaitForOptions } from './wait-for';\nimport { ErrorWithStack } from './helpers/errors';\n\nfunction isRemoved<T>(result: T): boolean {\n return !result || (Array.isArray(result) && !result.length);\n}\n\nexport default async function waitForElementToBeRemoved<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Created here so we get a nice stacktrace\n const timeoutError = new ErrorWithStack(\n 'Timed out in waitForElementToBeRemoved.',\n waitForElementToBeRemoved\n );\n\n // Elements have to be present initally and then removed.\n const initialElements = expectation();\n if (isRemoved(initialElements)) {\n throw new ErrorWithStack(\n 'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',\n waitForElementToBeRemoved\n );\n }\n\n return await waitFor(() => {\n let result;\n try {\n result = expectation();\n } catch (error) {\n return initialElements;\n }\n\n if (!isRemoved(result)) {\n throw timeoutError;\n }\n\n return initialElements;\n }, options);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,SAASG,SAASA,CAAIC,MAAS,EAAW;EACxC,OAAO,CAACA,MAAM,IAAKC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,IAAI,CAACA,MAAM,CAACG,MAAO;AAC7D;AAEe,eAAeC,yBAAyBA,CACrDC,WAAoB,EACpBC,OAAwB,EACZ;EACZ;EACA,MAAMC,YAAY,GAAG,IAAIC,sBAAc,CACrC,yCAAyC,EACzCJ,yBACF,CAAC;;EAED;EACA,MAAMK,eAAe,GAAGJ,WAAW,CAAC,CAAC;EACrC,IAAIN,SAAS,CAACU,eAAe,CAAC,EAAE;IAC9B,MAAM,IAAID,sBAAc,CACtB,oKAAoK,EACpKJ,yBACF,CAAC;EACH;EAEA,OAAO,MAAM,IAAAM,gBAAO,EAAC,MAAM;IACzB,IAAIV,MAAM;IACV,IAAI;MACFA,MAAM,GAAGK,WAAW,CAAC,CAAC;IACxB,CAAC,CAAC,OAAOM,KAAK,EAAE;MACd,OAAOF,eAAe;IACxB;IAEA,IAAI,CAACV,SAAS,CAACC,MAAM,CAAC,EAAE;MACtB,MAAMO,YAAY;IACpB;IAEA,OAAOE,eAAe;EACxB,CAAC,EAAEH,OAAO,CAAC;AACb"}
package/build/wait-for.js CHANGED
@@ -170,7 +170,7 @@ function waitForInternal(expectation, {
170
170
  }
171
171
  });
172
172
  }
173
- async function waitFor(expectation, options) {
173
+ function waitFor(expectation, options) {
174
174
  // Being able to display a useful stack trace requires generating it before doing anything async
175
175
  const stackTraceError = new _errors.ErrorWithStack('STACK_TRACE_ERROR', waitFor);
176
176
  const optionsWithStackTrace = {
@@ -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 { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n jestFakeTimersAreEnabled,\n} 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 // eslint-disable-next-line no-unmodified-loop-condition\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 // eslint-disable-next-line no-await-in-loop\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\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-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\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 async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): 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,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AATA;;AAWA,MAAMK,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;MACA;MACA;MACA,IAAIC,iBAAiB,GAAGlB,OAAO;MAC/B,OAAO,CAACY,QAAQ,EAAE;QAChB,IAAI,CAAC,IAAAI,gCAAwB,EAAC,CAAC,EAAE;UAC/B,MAAMG,KAAK,GAAG,IAAIC,KAAK,CACpB,kUACH,CAAC;UACD,IAAIhB,eAAe,EAAE;YACnB,IAAAiB,sBAAc,EAACF,KAAK,EAAEf,eAAe,CAAC;UACxC;UACAK,MAAM,CAACU,KAAK,CAAC;UACb;QACF;;QA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6B,MAAM,GAAG7B,SAAS,CAACc,KAAK,CAAC;QAC/B,IAAIe,MAAM,EAAE;UACVf,KAAK,GAAGe,MAAM;QAChB;MACF;MACAL,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAO;QAAEd;MAAM,CAAC,CAAC;IAClC;EACF,CAAC,CAAC;AACJ;AAEe,eAAeqB,OAAOA,CACnCzC,WAAoB,EACpB0C,OAAwB,EACZ;EACZ;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"}
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 { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n jestFakeTimersAreEnabled,\n} 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 // eslint-disable-next-line no-unmodified-loop-condition\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 // eslint-disable-next-line no-await-in-loop\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\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-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\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>(\n expectation: () => T,\n options?: WaitForOptions\n): 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,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AATA;;AAWA,MAAMK,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;MACA;MACA;MACA,IA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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,MAAM6B,MAAM,GAAG7B,SAAS,CAACc,KAAK,CAAC;QAC/B,IAAIe,MAAM,EAAE;UACVf,KAAK,GAAGe,MAAM;QAChB;MACF;MACAL,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAO;QAAEd;MAAM,CAAC,CAAC;IAClC;EACF,CAAC,CAAC;AACJ;AAEe,SAASqB,OAAOA,CAC7BzC,WAAoB,EACpB0C,OAAwB,EACZ;EACZ;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"}
@@ -0,0 +1 @@
1
+ export * from './build/matchers/extend-expect';
@@ -0,0 +1 @@
1
+ require('./build/matchers/extend-expect');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/react-native",
3
- "version": "12.3.2",
3
+ "version": "12.3.3",
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",
@@ -17,7 +17,6 @@
17
17
  "MattAgn <matthieua@bam.tech> (https://github.com/MattAgn)"
18
18
  ],
19
19
  "license": "MIT",
20
- "private": false,
21
20
  "keywords": [
22
21
  "react-native",
23
22
  "react",
@@ -27,10 +26,12 @@
27
26
  "files": [
28
27
  "build/",
29
28
  "jest-preset/",
30
- "typings/index.flow.js",
29
+ "extend-expect.js",
30
+ "extend-expect.d.ts",
31
31
  "pure.js",
32
32
  "pure.d.ts",
33
- "dont-cleanup-after-each.js"
33
+ "dont-cleanup-after-each.js",
34
+ "typings/index.flow.js"
34
35
  ],
35
36
  "devDependencies": {
36
37
  "@babel/cli": "^7.22.15",
@@ -40,7 +41,7 @@
40
41
  "@babel/preset-flow": "^7.22.15",
41
42
  "@babel/preset-react": "^7.22.15",
42
43
  "@babel/preset-typescript": "^7.22.15",
43
- "@callstack/eslint-config": "^13.0.1",
44
+ "@callstack/eslint-config": "^14.1.0",
44
45
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
45
46
  "@types/jest": "^29.5.5",
46
47
  "@types/react": "^18.2.21",
@@ -92,5 +93,6 @@
92
93
  "build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
93
94
  "build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
94
95
  "prepare": "yarn build"
95
- }
96
- }
96
+ },
97
+ "packageManager": "yarn@4.0.1"
98
+ }
@@ -0,0 +1,40 @@
1
+ import type { StyleProp } from 'react-native';
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ import type { TextMatch, TextMatchOptions } from '../matches';
4
+ import type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';
5
+ import type { Style } from './to-have-style';
6
+
7
+ export interface JestNativeMatchers<R> {
8
+ toBeOnTheScreen(): R;
9
+ toBeChecked(): R;
10
+ toBeCollapsed(): R;
11
+ toBeDisabled(): R;
12
+ toBeBusy(): R;
13
+ toBeEmptyElement(): R;
14
+ toBeEnabled(): R;
15
+ toBeExpanded(): R;
16
+ toBePartiallyChecked(): R;
17
+ toBeSelected(): R;
18
+ toBeVisible(): R;
19
+ toContainElement(element: ReactTestInstance | null): R;
20
+ toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;
21
+ toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;
22
+ toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;
23
+ toHaveProp(name: string, expectedValue?: unknown): R;
24
+ toHaveStyle(style: StyleProp<Style>): R;
25
+ toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;
26
+ }
27
+
28
+ // Implicit Jest global `expect`.
29
+ declare global {
30
+ namespace jest {
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}
33
+ }
34
+ }
35
+
36
+ // Explicit `@jest/globals` `expect` matchers.
37
+ declare module '@jest/expect' {
38
+ interface Matchers<R extends void | Promise<void>>
39
+ extends JestNativeMatchers<R> {}
40
+ }