@testing-library/react-native 10.0.1 → 11.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/build/cleanup.js +4 -0
- package/build/cleanup.js.map +1 -1
- package/build/fireEvent.js +15 -13
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/errors.js +1 -3
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/matchers/matchArrayProp.d.ts +8 -0
- package/build/helpers/matchers/matchArrayProp.js +26 -0
- package/build/helpers/matchers/matchArrayProp.js.map +1 -0
- package/build/helpers/matchers/matchObjectProp.d.ts +12 -0
- package/build/helpers/matchers/matchObjectProp.js +27 -0
- package/build/helpers/matchers/matchObjectProp.js.map +1 -0
- package/build/helpers/matchers/matchStringProp.d.ts +9 -0
- package/build/helpers/matchers/matchStringProp.js +26 -0
- package/build/helpers/matchers/matchStringProp.js.map +1 -0
- package/build/helpers/timers.js +12 -2
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +8 -24
- package/build/matches.js +2 -1
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +5 -2
- package/build/pure.js +8 -0
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.d.ts +18 -0
- package/build/queries/a11yState.js +53 -0
- package/build/queries/a11yState.js.map +1 -0
- package/build/queries/a11yValue.d.ts +24 -0
- package/build/queries/a11yValue.js +53 -0
- package/build/queries/a11yValue.js.map +1 -0
- package/build/queries/hintText.d.ts +24 -0
- package/build/queries/hintText.js +61 -0
- package/build/queries/hintText.js.map +1 -0
- package/build/queries/labelText.d.ts +12 -0
- package/build/queries/labelText.js +39 -0
- package/build/queries/labelText.js.map +1 -0
- package/build/queries/makeQueries.d.ts +6 -6
- package/build/queries/makeQueries.js +4 -36
- package/build/queries/makeQueries.js.map +1 -1
- package/build/queries/role.d.ts +12 -0
- package/build/queries/role.js +39 -0
- package/build/queries/role.js.map +1 -0
- package/build/queries/text.js +1 -3
- package/build/queries/text.js.map +1 -1
- package/build/render.d.ts +107 -64
- package/build/render.js +5 -1
- package/build/render.js.map +1 -1
- package/build/renderHook.js +2 -2
- package/build/renderHook.js.map +1 -1
- package/build/screen.d.ts +4 -0
- package/build/screen.js +127 -0
- package/build/screen.js.map +1 -0
- package/build/waitFor.js +1 -1
- package/build/waitFor.js.map +1 -1
- package/build/within.d.ts +106 -64
- package/build/within.js +16 -4
- package/build/within.js.map +1 -1
- package/package.json +21 -17
- package/typings/index.flow.js +8 -24
- package/build/queries/a11yAPI.d.ts +0 -66
- package/build/queries/a11yAPI.js +0 -94
- package/build/queries/a11yAPI.js.map +0 -1
- package/build/queries/makeA11yQuery.d.ts +0 -13
- package/build/queries/makeA11yQuery.js +0 -80
- package/build/queries/makeA11yQuery.js.map +0 -1
package/README.md
CHANGED
|
@@ -102,22 +102,20 @@ flow-typed install react-test-renderer
|
|
|
102
102
|
## Example
|
|
103
103
|
|
|
104
104
|
```jsx
|
|
105
|
-
import { render, fireEvent } from '@testing-library/react-native';
|
|
105
|
+
import { render, screen, fireEvent } from '@testing-library/react-native';
|
|
106
106
|
import { QuestionsBoard } from '../QuestionsBoard';
|
|
107
107
|
|
|
108
108
|
test('form submits two answers', () => {
|
|
109
109
|
const allQuestions = ['q1', 'q2'];
|
|
110
110
|
const mockFn = jest.fn();
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
<QuestionsBoard questions={allQuestions} onSubmit={mockFn} />
|
|
114
|
-
);
|
|
112
|
+
render(<QuestionsBoard questions={allQuestions} onSubmit={mockFn} />);
|
|
115
113
|
|
|
116
|
-
const answerInputs = getAllByLabelText('answer input');
|
|
114
|
+
const answerInputs = screen.getAllByLabelText('answer input');
|
|
117
115
|
|
|
118
116
|
fireEvent.changeText(answerInputs[0], 'a1');
|
|
119
117
|
fireEvent.changeText(answerInputs[1], 'a2');
|
|
120
|
-
fireEvent.press(getByText('Submit'));
|
|
118
|
+
fireEvent.press(screen.getByText('Submit'));
|
|
121
119
|
|
|
122
120
|
expect(mockFn).toBeCalledWith({
|
|
123
121
|
'1': { q: 'q1', a: 'a1' },
|
|
@@ -143,6 +141,10 @@ The [public API](https://callstack.github.io/react-native-testing-library/docs/a
|
|
|
143
141
|
- [Migration to 7.0](https://callstack.github.io/react-native-testing-library/docs/migration-v7)
|
|
144
142
|
- [Migration to 2.0](https://callstack.github.io/react-native-testing-library/docs/migration-v2)
|
|
145
143
|
|
|
144
|
+
## Troubleshooting
|
|
145
|
+
|
|
146
|
+
- [Understanding `act` function](https://callstack.github.io/react-native-testing-library/docs/undestanding-act)
|
|
147
|
+
|
|
146
148
|
## Related External Resources
|
|
147
149
|
|
|
148
150
|
- [Real world extensive examples repo](https://github.com/vanGalilea/react-native-testing)
|
package/build/cleanup.js
CHANGED
|
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.addToCleanupQueue = addToCleanupQueue;
|
|
7
7
|
exports.default = cleanup;
|
|
8
|
+
|
|
9
|
+
var _screen = require("./screen");
|
|
10
|
+
|
|
8
11
|
let cleanupQueue = new Set();
|
|
9
12
|
|
|
10
13
|
function cleanup() {
|
|
14
|
+
(0, _screen.clearRenderResult)();
|
|
11
15
|
cleanupQueue.forEach(fn => fn());
|
|
12
16
|
cleanupQueue.clear();
|
|
13
17
|
}
|
package/build/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cleanup.ts"],"names":["cleanupQueue","Set","cleanup","forEach","fn","clear","addToCleanupQueue","add"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/cleanup.ts"],"names":["cleanupQueue","Set","cleanup","forEach","fn","clear","addToCleanupQueue","add"],"mappings":";;;;;;;;AACA;;AAGA,IAAIA,YAAY,GAAG,IAAIC,GAAJ,EAAnB;;AAEe,SAASC,OAAT,GAAmB;AAChC;AACAF,EAAAA,YAAY,CAACG,OAAb,CAAsBC,EAAD,IAAQA,EAAE,EAA/B;AACAJ,EAAAA,YAAY,CAACK,KAAb;AACD;;AAEM,SAASC,iBAAT,CAA2BF,EAA3B,EAAgD;AACrDJ,EAAAA,YAAY,CAACO,GAAb,CAAiBH,EAAjB;AACD","sourcesContent":["import * as React from 'react';\nimport { clearRenderResult } from './screen';\n\ntype CleanUpFunction = (nextElement?: React.ReactElement<any>) => void;\nlet cleanupQueue = new Set<CleanUpFunction>();\n\nexport default function cleanup() {\n clearRenderResult();\n cleanupQueue.forEach((fn) => fn());\n cleanupQueue.clear();\n}\n\nexport function addToCleanupQueue(fn: CleanUpFunction) {\n cleanupQueue.add(fn);\n}\n"],"file":"cleanup.js"}
|
package/build/fireEvent.js
CHANGED
|
@@ -10,7 +10,7 @@ var _act = _interopRequireDefault(require("./act"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
12
|
const isHostElement = element => {
|
|
13
|
-
return typeof
|
|
13
|
+
return typeof element?.type === 'string';
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const isTextInput = element => {
|
|
@@ -18,32 +18,34 @@ const isTextInput = element => {
|
|
|
18
18
|
TextInput
|
|
19
19
|
} = require('react-native');
|
|
20
20
|
|
|
21
|
-
return
|
|
21
|
+
return element?.type === TextInput;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const isTouchResponder = element => {
|
|
25
25
|
if (!isHostElement(element)) return false;
|
|
26
|
-
return !!
|
|
26
|
+
return !!element?.props.onStartShouldSetResponder || isTextInput(element);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const isPointerEventEnabled = (element, isParent) => {
|
|
30
|
-
const parentCondition = isParent ?
|
|
30
|
+
const parentCondition = isParent ? element?.props.pointerEvents === 'box-only' : element?.props.pointerEvents === 'box-none';
|
|
31
31
|
|
|
32
|
-
if (
|
|
32
|
+
if (element?.props.pointerEvents === 'none' || parentCondition) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (!
|
|
36
|
+
if (!element?.parent) return true;
|
|
37
37
|
return isPointerEventEnabled(element.parent, true);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const isTouchEvent = eventName => {
|
|
41
|
+
return eventName === 'press';
|
|
42
|
+
};
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
const
|
|
44
|
+
const isEventEnabled = (element, touchResponder, eventName) => {
|
|
45
|
+
if (isTextInput(element)) return element?.props.editable !== false;
|
|
46
|
+
if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;
|
|
47
|
+
const touchStart = touchResponder?.props.onStartShouldSetResponder?.();
|
|
48
|
+
const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();
|
|
47
49
|
if (touchStart || touchMove) return true;
|
|
48
50
|
return touchStart === undefined && touchMove === undefined;
|
|
49
51
|
};
|
|
@@ -51,7 +53,7 @@ const isEventEnabled = (element, touchResponder) => {
|
|
|
51
53
|
const findEventHandler = (element, eventName, callsite, nearestTouchResponder) => {
|
|
52
54
|
const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
|
|
53
55
|
const handler = getEventHandler(element, eventName);
|
|
54
|
-
if (handler && isEventEnabled(element, touchResponder)) return handler;
|
|
56
|
+
if (handler && isEventEnabled(element, touchResponder, eventName)) return handler;
|
|
55
57
|
|
|
56
58
|
if (element.parent === null || element.parent.parent === null) {
|
|
57
59
|
return null;
|
package/build/fireEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fireEvent.ts"],"names":["isHostElement","element","type","isTextInput","TextInput","require","isTouchResponder","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","
|
|
1
|
+
{"version":3,"sources":["../src/fireEvent.ts"],"names":["isHostElement","element","type","isTextInput","TextInput","require","isTouchResponder","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isTouchEvent","eventName","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","callsite","nearestTouchResponder","handler","getEventHandler","eventHandlerName","toEventHandlerName","invokeEvent","data","returnValue","charAt","toUpperCase","slice","pressHandler","changeTextHandler","scrollHandler","fireEvent","press","changeText","scroll"],"mappings":";;;;;;;AACA;;;;AAIA,MAAMA,aAAa,GAAIC,OAAD,IAAiC;AACrD,SAAO,OAAOA,OAAO,EAAEC,IAAhB,KAAyB,QAAhC;AACD,CAFD;;AAIA,MAAMC,WAAW,GAAIF,OAAD,IAAiC;AACnD,QAAM;AAAEG,IAAAA;AAAF,MAAgBC,OAAO,CAAC,cAAD,CAA7B;;AACA,SAAOJ,OAAO,EAAEC,IAAT,KAAkBE,SAAzB;AACD,CAHD;;AAKA,MAAME,gBAAgB,GAAIL,OAAD,IAAiC;AACxD,MAAI,CAACD,aAAa,CAACC,OAAD,CAAlB,EAA6B,OAAO,KAAP;AAE7B,SAAO,CAAC,CAACA,OAAO,EAAEM,KAAT,CAAeC,yBAAjB,IAA8CL,WAAW,CAACF,OAAD,CAAhE;AACD,CAJD;;AAMA,MAAMQ,qBAAqB,GAAG,CAC5BR,OAD4B,EAE5BS,QAF4B,KAGhB;AACZ,QAAMC,eAAe,GAAGD,QAAQ,GAC5BT,OAAO,EAAEM,KAAT,CAAeK,aAAf,KAAiC,UADL,GAE5BX,OAAO,EAAEM,KAAT,CAAeK,aAAf,KAAiC,UAFrC;;AAIA,MAAIX,OAAO,EAAEM,KAAT,CAAeK,aAAf,KAAiC,MAAjC,IAA2CD,eAA/C,EAAgE;AAC9D,WAAO,KAAP;AACD;;AAED,MAAI,CAACV,OAAO,EAAEY,MAAd,EAAsB,OAAO,IAAP;AAEtB,SAAOJ,qBAAqB,CAACR,OAAO,CAACY,MAAT,EAAiB,IAA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AAxB,EAA2C,GAAGN,IAA9C,CAHtB;;AAIA,MAAMO,aAAa,GAAG,CAACrC,OAAD,EAA6B,GAAG8B,IAAhC,KACpBD,WAAW,CAAC7B,OAAD,EAAU,QAAV,EAAoBqC,aAApB,EAAmC,GAAGP,IAAtC,CADb;;AAGA,MAAMQ,SAAS,GAAG,CAChBtC,OADgB,EAEhBc,SAFgB,EAGhB,GAAGgB,IAHa,KAIPD,WAAW,CAAC7B,OAAD,EAAUc,SAAV,EAAqBwB,SAArB,EAAgC,GAAGR,IAAnC,CAJtB;;AAMAQ,SAAS,CAACC,KAAV,GAAkBJ,YAAlB;AACAG,SAAS,CAACE,UAAV,GAAuBJ,iBAAvB;AACAE,SAAS,CAACG,MAAV,GAAmBJ,aAAnB;eAEeC,S","sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from './act';\n\ntype EventHandler = (...args: any) => unknown;\n\nconst isHostElement = (element?: ReactTestInstance) => {\n return typeof element?.type === 'string';\n};\n\nconst isTextInput = (element?: ReactTestInstance) => {\n const { TextInput } = require('react-native');\n return element?.type === TextInput;\n};\n\nconst isTouchResponder = (element?: ReactTestInstance) => {\n if (!isHostElement(element)) return false;\n\n return !!element?.props.onStartShouldSetResponder || isTextInput(element);\n};\n\nconst isPointerEventEnabled = (\n element?: ReactTestInstance,\n isParent?: boolean\n): boolean => {\n const parentCondition = isParent\n ? element?.props.pointerEvents === 'box-only'\n : element?.props.pointerEvents === 'box-none';\n\n if (element?.props.pointerEvents === 'none' || parentCondition) {\n return false;\n }\n\n if (!element?.parent) return true;\n\n return isPointerEventEnabled(element.parent, true);\n};\n\nconst isTouchEvent = (eventName?: string) => {\n return eventName === 'press';\n};\n\nconst isEventEnabled = (\n element?: ReactTestInstance,\n touchResponder?: ReactTestInstance,\n eventName?: string\n) => {\n if (isTextInput(element)) return element?.props.editable !== false;\n if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;\n\n const touchStart = touchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();\n\n if (touchStart || touchMove) return true;\n\n return touchStart === undefined && touchMove === undefined;\n};\n\nconst findEventHandler = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\n nearestTouchResponder?: ReactTestInstance\n): EventHandler | null => {\n const touchResponder = isTouchResponder(element)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, touchResponder, eventName))\n return handler;\n\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, callsite, touchResponder);\n};\n\nconst getEventHandler = (\n element: ReactTestInstance,\n eventName: string\n): EventHandler | undefined => {\n const eventHandlerName = toEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n};\n\nconst invokeEvent = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\n ...data: Array<any>\n) => {\n const handler = findEventHandler(element, eventName, callsite);\n\n if (!handler) {\n return;\n }\n\n let returnValue;\n\n act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n};\n\nconst toEventHandlerName = (eventName: string) =>\n `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n\nconst pressHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'press', pressHandler, ...data);\nconst changeTextHandler = (\n element: ReactTestInstance,\n ...data: Array<any>\n): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);\nconst scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'scroll', scrollHandler, ...data);\n\nconst fireEvent = (\n element: ReactTestInstance,\n eventName: string,\n ...data: Array<any>\n): void => invokeEvent(element, eventName, fireEvent, ...data);\n\nfireEvent.press = pressHandler;\nfireEvent.changeText = changeTextHandler;\nfireEvent.scroll = scrollHandler;\n\nexport default fireEvent;\n"],"file":"fireEvent.js"}
|
package/build/helpers/errors.js
CHANGED
|
@@ -55,8 +55,6 @@ const prepareErrorMessage = (error, name, value) => {
|
|
|
55
55
|
exports.prepareErrorMessage = prepareErrorMessage;
|
|
56
56
|
|
|
57
57
|
const createQueryByError = (error, callsite) => {
|
|
58
|
-
var _toString, _ref;
|
|
59
|
-
|
|
60
58
|
if (error instanceof Error) {
|
|
61
59
|
if (error.message.includes('No instances found')) {
|
|
62
60
|
return null;
|
|
@@ -67,7 +65,7 @@ const createQueryByError = (error, callsite) => {
|
|
|
67
65
|
|
|
68
66
|
throw new ErrorWithStack( // generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that
|
|
69
67
|
// Converting as any with extra safe optional chaining will do the job just as well
|
|
70
|
-
`Query: caught unknown error type: ${typeof error}, value: ${error
|
|
68
|
+
`Query: caught unknown error type: ${typeof error}, value: ${error?.toString?.()}`, callsite);
|
|
71
69
|
};
|
|
72
70
|
|
|
73
71
|
exports.createQueryByError = createQueryByError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/errors.ts"],"names":["ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","createLibraryNotSupportedError","error","prepareErrorMessage","name","value","errorMessage","replace","toString","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack","warned","printDeprecationWarning","functionName","console","warn","throwRemovedFunctionError","docsRef","throwRenamedFunctionError","newFunctionName"],"mappings":";;;;;;;;;;;;AAAA;;;;AAEO,MAAMA,cAAN,SAA6BC,KAA7B,CAAmC;AACxCC,EAAAA,WAAW,CAACC,OAAD,EAA8BC,QAA9B,EAAkD;AAC3D,UAAMD,OAAN;;AACA,QAAIF,KAAK,CAACI,iBAAV,EAA6B;AAC3BJ,MAAAA,KAAK,CAACI,iBAAN,CAAwB,IAAxB,EAA8BD,QAA9B;AACD;AACF;;AANuC;;;;AASnC,MAAME,8BAA8B,GAAIC,KAAD,IAC5C,IAAIN,KAAJ,CACG,gFACCM,KAAK,YAAYN,KAAjB,GAAyBM,KAAK,CAACJ,OAA/B,GAAyC,EAC1C,EAHH,CADK;;;;AAOA,MAAMK,mBAAmB,GAAG,CAGjCD,KAHiC,EAIjCE,IAJiC,EAKjCC,KALiC,KAMtB;AACX,MAAIC,YAAJ;;AACA,MAAIJ,KAAK,YAAYN,KAArB,EAA4B;AAC1B;AACAU,IAAAA,YAAY,GAAGJ,KAAK,CAACJ,OAAN,CAAcS,OAAd,CACb,kCADa,EAEb,EAFa,CAAf;AAID,GAND,MAMO,IAAIL,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA9B,EAAwC;AAC7CI,IAAAA,YAAY,GAAGJ,KAAK,CAACM,QAAN,EAAf;AACD,GAFM,MAEA;AACLF,IAAAA,YAAY,GAAG,sBAAf;AACD;;AAED,MAAIF,IAAI,IAAIC,KAAZ,EAAmB;AACjBC,IAAAA,YAAY,IAAK,SAAQF,IAAK,IAAG,2BAAaC,KAAb,EAAoB;AAAEI,MAAAA,GAAG,EAAE;AAAP,KAApB,CAAmC,EAApE;AACD;;AACD,SAAOH,YAAP;AACD,CAxBM;;;;AA0BA,MAAMI,kBAAkB,GAAG,CAChCR,KADgC,EAEhCH,QAFgC,KAGvB;
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/errors.ts"],"names":["ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","createLibraryNotSupportedError","error","prepareErrorMessage","name","value","errorMessage","replace","toString","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack","warned","printDeprecationWarning","functionName","console","warn","throwRemovedFunctionError","docsRef","throwRenamedFunctionError","newFunctionName"],"mappings":";;;;;;;;;;;;AAAA;;;;AAEO,MAAMA,cAAN,SAA6BC,KAA7B,CAAmC;AACxCC,EAAAA,WAAW,CAACC,OAAD,EAA8BC,QAA9B,EAAkD;AAC3D,UAAMD,OAAN;;AACA,QAAIF,KAAK,CAACI,iBAAV,EAA6B;AAC3BJ,MAAAA,KAAK,CAACI,iBAAN,CAAw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;;;AAmBA,SAASa,cAAT,CAAwBC,MAAxB,EAAyCC,gBAAzC,EAAkE;AACvE,MAAID,MAAM,YAAYjB,KAAlB,IAA2BkB,gBAAgB,CAACC,KAAhD,EAAuD;AACrDF,IAAAA,MAAM,CAACE,KAAP,GAAeD,gBAAgB,CAACC,KAAjB,CAAuBR,OAAvB,CACbO,gBAAgB,CAAChB,OADJ,EAEbe,MAAM,CAACf,OAFM,CAAf;AAID;AACF;;AAED,MAAMkB,MAA2C,GAAG,EAApD;;AAEO,SAASC,uBAAT,CAAiCC,YAAjC,EAAuD;AAC5D,MAAIF,MAAM,CAACE,YAAD,CAAV,EAA0B;AACxB;AACD,GAH2D,CAK5D;;;AACAC,EAAAA,OAAO,CAACC,IAAR,CAAc;AAChB;AACA,WAAWF,YAAa;AACxB,GAHE;AAKAF,EAAAA,MAAM,CAACE,YAAD,CAAN,GAAuB,IAAvB;AACD;;AAEM,SAASG,yBAAT,CACLH,YADK,EAELI,OAFK,EAGL;AACA,QAAM,IAAI1B,KAAJ,CACH,IAAGsB,YAAa,wGAAuGI,OAAQ,EAD5H,CAAN;AAGD;;AAEM,SAASC,yBAAT,CACLL,YADK,EAELM,eAFK,EAGL;AACA,QAAM,IAAI7B,cAAJ,CACH,QAAOuB,YAAa,mCAAkCM,eAAgB,oCADnE,EAEJD,yBAFI,CAAN;AAID","sourcesContent":["import prettyFormat from 'pretty-format';\n\nexport class ErrorWithStack extends Error {\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport const createLibraryNotSupportedError = (error: unknown): Error =>\n new Error(\n `Currently the only supported library to search by text is \"react-native\".\\n\\n${\n error instanceof Error ? error.message : ''\n }`\n );\n\nexport const prepareErrorMessage = (\n // TS states that error caught in a catch close are of type `unknown`\n // most real cases will be `Error`, but better safe than sorry\n error: unknown,\n name?: string,\n value?: unknown\n): string => {\n let errorMessage: string;\n if (error instanceof Error) {\n // Strip info about custom predicate\n errorMessage = error.message.replace(\n / matching custom predicate[^]*/gm,\n ''\n );\n } else if (error && typeof error === 'object') {\n errorMessage = error.toString();\n } else {\n errorMessage = 'Caught unknown error';\n }\n\n if (name && value) {\n errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;\n }\n return errorMessage;\n};\n\nexport const createQueryByError = (\n error: NonNullable<unknown>,\n callsite: Function\n): null => {\n if (error instanceof Error) {\n if (error.message.includes('No instances found')) {\n return null;\n }\n throw new ErrorWithStack(error.message, callsite);\n }\n\n throw new ErrorWithStack(\n // generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that\n // Converting as any with extra safe optional chaining will do the job just as well\n `Query: caught unknown error type: ${typeof error}, value: ${(error as any)?.toString?.()}`,\n callsite\n );\n};\n\nexport function copyStackTrace(target: unknown, stackTraceSource: Error) {\n if (target instanceof Error && stackTraceSource.stack) {\n target.stack = stackTraceSource.stack.replace(\n stackTraceSource.message,\n target.message\n );\n }\n}\n\nconst warned: { [functionName: string]: boolean } = {};\n\nexport function printDeprecationWarning(functionName: string) {\n if (warned[functionName]) {\n return;\n }\n\n // eslint-disable-next-line no-console\n console.warn(`\n Deprecation Warning:\n Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.\n `);\n\n warned[functionName] = true;\n}\n\nexport function throwRemovedFunctionError(\n functionName: string,\n docsRef: string\n) {\n throw new Error(\n `\"${functionName}\" has been removed.\\n\\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`\n );\n}\n\nexport function throwRenamedFunctionError(\n functionName: string,\n newFunctionName: string\n) {\n throw new ErrorWithStack(\n `The \"${functionName}\" function has been renamed to \"${newFunctionName}\". Please replace all occurrences.`,\n throwRenamedFunctionError\n );\n}\n"],"file":"errors.js"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches whether given array prop contains the given value, or all given values.
|
|
3
|
+
*
|
|
4
|
+
* @param prop - The array prop to match.
|
|
5
|
+
* @param matcher - The value or values to be included in the array.
|
|
6
|
+
* @returns Whether the array prop contains the given value, or all given values.
|
|
7
|
+
*/
|
|
8
|
+
export declare function matchArrayProp(prop: Array<string> | undefined, matcher: string | Array<string>): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchArrayProp = matchArrayProp;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Matches whether given array prop contains the given value, or all given values.
|
|
10
|
+
*
|
|
11
|
+
* @param prop - The array prop to match.
|
|
12
|
+
* @param matcher - The value or values to be included in the array.
|
|
13
|
+
* @returns Whether the array prop contains the given value, or all given values.
|
|
14
|
+
*/
|
|
15
|
+
function matchArrayProp(prop, matcher) {
|
|
16
|
+
if (!prop || matcher.length === 0) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof matcher === 'string') {
|
|
21
|
+
return prop.includes(matcher);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return matcher.every(e => prop.includes(e));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=matchArrayProp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/helpers/matchers/matchArrayProp.ts"],"names":["matchArrayProp","prop","matcher","length","includes","every","e"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CACLC,IADK,EAELC,OAFK,EAGI;AACT,MAAI,CAACD,IAAD,IAASC,OAAO,CAACC,MAAR,KAAmB,CAAhC,EAAmC;AACjC,WAAO,KAAP;AACD;;AAED,MAAI,OAAOD,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAOD,IAAI,CAACG,QAAL,CAAcF,OAAd,CAAP;AACD;;AAED,SAAOA,OAAO,CAACG,KAAR,CAAeC,CAAD,IAAOL,IAAI,CAACG,QAAL,CAAcE,CAAd,CAArB,CAAP;AACD","sourcesContent":["/**\n * Matches whether given array prop contains the given value, or all given values.\n *\n * @param prop - The array prop to match.\n * @param matcher - The value or values to be included in the array.\n * @returns Whether the array prop contains the given value, or all given values.\n */\nexport function matchArrayProp(\n prop: Array<string> | undefined,\n matcher: string | Array<string>\n): boolean {\n if (!prop || matcher.length === 0) {\n return false;\n }\n\n if (typeof matcher === 'string') {\n return prop.includes(matcher);\n }\n\n return matcher.every((e) => prop.includes(e));\n}\n"],"file":"matchArrayProp.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check that each key value pair of the objects match
|
|
3
|
+
* BE CAREFUL it works only for 1 level deep key value pairs
|
|
4
|
+
* won't work for nested objects
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Matches whether given object prop contains all key/value pairs.
|
|
8
|
+
* @param prop - The object prop to match.
|
|
9
|
+
* @param matcher - The key/value pairs to be included in the object.
|
|
10
|
+
* @returns Whether the object prop contains all key/value pairs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchObjectProp<T extends Record<string, unknown>>(prop: T | undefined, matcher: T): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchObjectProp = matchObjectProp;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* check that each key value pair of the objects match
|
|
10
|
+
* BE CAREFUL it works only for 1 level deep key value pairs
|
|
11
|
+
* won't work for nested objects
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Matches whether given object prop contains all key/value pairs.
|
|
16
|
+
* @param prop - The object prop to match.
|
|
17
|
+
* @param matcher - The key/value pairs to be included in the object.
|
|
18
|
+
* @returns Whether the object prop contains all key/value pairs.
|
|
19
|
+
*/
|
|
20
|
+
function matchObjectProp(prop, matcher) {
|
|
21
|
+
if (!prop || Object.keys(matcher).length === 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Object.keys(prop).length !== 0 && Object.keys(matcher).every(key => prop[key] === matcher[key]);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=matchObjectProp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/helpers/matchers/matchObjectProp.ts"],"names":["matchObjectProp","prop","matcher","Object","keys","length","every","key"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CACLC,IADK,EAELC,OAFK,EAGI;AACT,MAAI,CAACD,IAAD,IAASE,MAAM,CAACC,IAAP,CAAYF,OAAZ,EAAqBG,MAArB,KAAgC,CAA7C,EAAgD;AAC9C,WAAO,KAAP;AACD;;AAED,SACEF,MAAM,CAACC,IAAP,CAAYH,IAAZ,EAAkBI,MAAlB,KAA6B,CAA7B,IACAF,MAAM,CAACC,IAAP,CAAYF,OAAZ,EAAqBI,KAArB,CAA4BC,GAAD,IAASN,IAAI,CAACM,GAAD,CAAJ,KAAcL,OAAO,CAACK,GAAD,CAAzD,CAFF;AAID","sourcesContent":["/**\n * check that each key value pair of the objects match\n * BE CAREFUL it works only for 1 level deep key value pairs\n * won't work for nested objects\n */\n\n/**\n * Matches whether given object prop contains all key/value pairs.\n * @param prop - The object prop to match.\n * @param matcher - The key/value pairs to be included in the object.\n * @returns Whether the object prop contains all key/value pairs.\n */\nexport function matchObjectProp<T extends Record<string, unknown>>(\n prop: T | undefined,\n matcher: T\n): boolean {\n if (!prop || Object.keys(matcher).length === 0) {\n return false;\n }\n\n return (\n Object.keys(prop).length !== 0 &&\n Object.keys(matcher).every((key) => prop[key] === matcher[key])\n );\n}\n"],"file":"matchObjectProp.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextMatch } from '../../matches';
|
|
2
|
+
/**
|
|
3
|
+
* Matches the given string property again string or regex matcher.
|
|
4
|
+
*
|
|
5
|
+
* @param prop - The string prop to match.
|
|
6
|
+
* @param matcher - The string or regex to match.
|
|
7
|
+
* @returns - Whether the string prop matches the given string or regex.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchStringProp(prop: string | undefined, matcher: TextMatch): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchStringProp = matchStringProp;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Matches the given string property again string or regex matcher.
|
|
10
|
+
*
|
|
11
|
+
* @param prop - The string prop to match.
|
|
12
|
+
* @param matcher - The string or regex to match.
|
|
13
|
+
* @returns - Whether the string prop matches the given string or regex.
|
|
14
|
+
*/
|
|
15
|
+
function matchStringProp(prop, matcher) {
|
|
16
|
+
if (!prop) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof matcher === 'string') {
|
|
21
|
+
return prop === matcher;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return prop.match(matcher) != null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=matchStringProp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/helpers/matchers/matchStringProp.ts"],"names":["matchStringProp","prop","matcher","match"],"mappings":";;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CACLC,IADK,EAELC,OAFK,EAGI;AACT,MAAI,CAACD,IAAL,EAAW;AACT,WAAO,KAAP;AACD;;AAED,MAAI,OAAOC,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAOD,IAAI,KAAKC,OAAhB;AACD;;AAED,SAAOD,IAAI,CAACE,KAAL,CAAWD,OAAX,KAAuB,IAA9B;AACD","sourcesContent":["import { TextMatch } from '../../matches';\n\n/**\n * Matches the given string property again string or regex matcher.\n *\n * @param prop - The string prop to match.\n * @param matcher - The string or regex to match.\n * @returns - Whether the string prop matches the given string or regex.\n */\nexport function matchStringProp(\n prop: string | undefined,\n matcher: TextMatch\n): boolean {\n if (!prop) {\n return false;\n }\n\n if (typeof matcher === 'string') {\n return prop === matcher;\n }\n\n return prop.match(matcher) != null;\n}\n"],"file":"matchStringProp.js"}
|
package/build/helpers/timers.js
CHANGED
|
@@ -9,8 +9,9 @@ exports.setTimeout = exports.setImmediate = void 0;
|
|
|
9
9
|
// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
|
|
10
10
|
|
|
11
11
|
/* globals jest */
|
|
12
|
-
const globalObj = typeof window === 'undefined' ? global : window;
|
|
12
|
+
const globalObj = typeof window === 'undefined' ? global : window;
|
|
13
13
|
|
|
14
|
+
// Currently this fn only supports jest timers, but it could support other test runners in the future.
|
|
14
15
|
function runWithRealTimers(callback) {
|
|
15
16
|
const fakeTimersType = getJestFakeTimersType();
|
|
16
17
|
|
|
@@ -21,7 +22,8 @@ function runWithRealTimers(callback) {
|
|
|
21
22
|
const callbackReturnValue = callback();
|
|
22
23
|
|
|
23
24
|
if (fakeTimersType) {
|
|
24
|
-
|
|
25
|
+
const fakeTimersConfig = getFakeTimersConfigFromType(fakeTimersType);
|
|
26
|
+
jest.useFakeTimers(fakeTimersConfig);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
return callbackReturnValue;
|
|
@@ -52,6 +54,14 @@ function getJestFakeTimersType() {
|
|
|
52
54
|
return null;
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
function getFakeTimersConfigFromType(type) {
|
|
58
|
+
return type === 'legacy' ? {
|
|
59
|
+
legacyFakeTimers: true
|
|
60
|
+
} : {
|
|
61
|
+
legacyFakeTimers: false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
const jestFakeTimersAreEnabled = () => Boolean(getJestFakeTimersType()); // we only run our tests in node, and setImmediate is supported in node.
|
|
56
66
|
|
|
57
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/timers.ts"],"names":["globalObj","window","global","runWithRealTimers","callback","fakeTimersType","getJestFakeTimersType","jest","useRealTimers","callbackReturnValue","useFakeTimers","setTimeout","_isMockFunction","clock","getRealSystemTime","jestFakeTimersAreEnabled","Boolean","setImmediatePolyfill","fn","bindTimeFunctions","clearTimeoutFn","clearTimeout","setImmediateFn","setImmediate","setTimeoutFn"],"mappings":";;;;;;;;AAAA;;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAA3D
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/timers.ts"],"names":["globalObj","window","global","runWithRealTimers","callback","fakeTimersType","getJestFakeTimersType","jest","useRealTimers","callbackReturnValue","fakeTimersConfig","getFakeTimersConfigFromType","useFakeTimers","setTimeout","_isMockFunction","clock","getRealSystemTime","type","legacyFakeTimers","jestFakeTimersAreEnabled","Boolean","setImmediatePolyfill","fn","bindTimeFunctions","clearTimeoutFn","clearTimeout","setImmediateFn","setImmediate","setTimeoutFn"],"mappings":";;;;;;;;AAAA;;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAA3D;;AAIA;AACA,SAASE,iBAAT,CAA8BC,QAA9B,EAAoD;AAClD,QAAMC,cAAc,GAAGC,qBAAqB,EAA5C;;AACA,MAAID,cAAJ,EAAoB;AAClBE,IAAAA,IAAI,CAACC,aAAL;AACD;;AAED,QAAMC,mBAAmB,GAAGL,QAAQ,EAApC;;AAEA,MAAIC,cAAJ,EAAoB;AAClB,UAAMK,gBAAgB,GAAGC,2BAA2B,CAACN,cAAD,CAApD;AACAE,IAAAA,IAAI,CA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B;AAAkCE,EAAAA;AAAlC,IAAmDzB,iBAAiB,CACxEoB,iBADwE,CAA1E","sourcesContent":["// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js\n/* globals jest */\nconst globalObj = typeof window === 'undefined' ? global : window;\n\ntype FakeTimersTypes = 'modern' | 'legacy';\n\n// Currently this fn only supports jest timers, but it could support other test runners in the future.\nfunction runWithRealTimers<T>(callback: () => T): T {\n const fakeTimersType = getJestFakeTimersType();\n if (fakeTimersType) {\n jest.useRealTimers();\n }\n\n const callbackReturnValue = callback();\n\n if (fakeTimersType) {\n const fakeTimersConfig = getFakeTimersConfigFromType(fakeTimersType);\n jest.useFakeTimers(fakeTimersConfig);\n }\n\n return callbackReturnValue;\n}\n\nfunction getJestFakeTimersType(): FakeTimersTypes | null {\n // istanbul ignore if\n if (\n typeof jest === 'undefined' ||\n typeof globalObj.setTimeout === 'undefined'\n ) {\n return null;\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&\n // @ts-expect-error jest mutates setTimeout\n globalObj.setTimeout._isMockFunction\n ) {\n return 'legacy';\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout.clock !== 'undefined' &&\n typeof jest.getRealSystemTime !== 'undefined'\n ) {\n try {\n // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws\n jest.getRealSystemTime();\n return 'modern';\n } catch {\n // not using Jest's modern fake timers\n }\n }\n\n return null;\n}\n\nfunction getFakeTimersConfigFromType(type: FakeTimersTypes) {\n return type === 'legacy'\n ? { legacyFakeTimers: true }\n : { legacyFakeTimers: false };\n}\n\nconst jestFakeTimersAreEnabled = (): boolean =>\n Boolean(getJestFakeTimersType());\n\n// we only run our tests in node, and setImmediate is supported in node.\nfunction setImmediatePolyfill(fn: Function) {\n return globalObj.setTimeout(fn, 0);\n}\n\ntype BindTimeFunctions = {\n clearTimeoutFn: typeof clearTimeout;\n setImmediateFn: typeof setImmediate;\n setTimeoutFn: typeof setTimeout;\n};\n\nfunction bindTimeFunctions(): BindTimeFunctions {\n return {\n clearTimeoutFn: globalObj.clearTimeout,\n setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,\n setTimeoutFn: globalObj.setTimeout,\n };\n}\n\nconst { clearTimeoutFn, setImmediateFn, setTimeoutFn } = runWithRealTimers(\n bindTimeFunctions\n) as BindTimeFunctions;\n\nexport {\n runWithRealTimers,\n jestFakeTimersAreEnabled,\n clearTimeoutFn as clearTimeout,\n setImmediateFn as setImmediate,\n setTimeoutFn as setTimeout,\n};\n"],"file":"timers.js"}
|
package/build/index.flow.js
CHANGED
|
@@ -56,16 +56,6 @@ declare type A11yState = {|
|
|
|
56
56
|
expanded?: boolean,
|
|
57
57
|
|};
|
|
58
58
|
|
|
59
|
-
declare type A11yStates =
|
|
60
|
-
| 'disabled'
|
|
61
|
-
| 'selected'
|
|
62
|
-
| 'checked'
|
|
63
|
-
| 'unchecked'
|
|
64
|
-
| 'busy'
|
|
65
|
-
| 'expanded'
|
|
66
|
-
| 'collapsed'
|
|
67
|
-
| 'hasPopup';
|
|
68
|
-
|
|
69
59
|
declare type A11yValue = {
|
|
70
60
|
min?: number,
|
|
71
61
|
max?: number,
|
|
@@ -266,25 +256,17 @@ interface A11yAPI {
|
|
|
266
256
|
waitForOptions?: WaitForOptions
|
|
267
257
|
) => FindAllReturn;
|
|
268
258
|
|
|
269
|
-
// States
|
|
270
|
-
getByA11yStates: (matcher: A11yStates | Array<A11yStates>) => GetReturn;
|
|
271
|
-
getAllByA11yStates: (matcher: A11yStates | Array<A11yStates>) => GetAllReturn;
|
|
272
|
-
queryByA11yStates: (matcher: A11yStates | Array<A11yStates>) => QueryReturn;
|
|
273
|
-
queryAllByA11yStates: (
|
|
274
|
-
matcher: A11yStates | Array<A11yStates>
|
|
275
|
-
) => QueryAllReturn;
|
|
276
|
-
|
|
277
259
|
// State
|
|
278
|
-
getByA11yState: (matcher:
|
|
279
|
-
getAllByA11yState: (matcher:
|
|
280
|
-
queryByA11yState: (matcher:
|
|
281
|
-
queryAllByA11yState: (matcher:
|
|
260
|
+
getByA11yState: (matcher: A11yState) => GetReturn;
|
|
261
|
+
getAllByA11yState: (matcher: A11yState) => GetAllReturn;
|
|
262
|
+
queryByA11yState: (matcher: A11yState) => QueryReturn;
|
|
263
|
+
queryAllByA11yState: (matcher: A11yState) => QueryAllReturn;
|
|
282
264
|
findByA11yState: (
|
|
283
|
-
matcher:
|
|
265
|
+
matcher: A11yState,
|
|
284
266
|
waitForOptions?: WaitForOptions
|
|
285
267
|
) => FindReturn;
|
|
286
268
|
findAllByA11yState: (
|
|
287
|
-
matcher:
|
|
269
|
+
matcher: A11yState,
|
|
288
270
|
waitForOptions?: WaitForOptions
|
|
289
271
|
) => FindAllReturn;
|
|
290
272
|
|
|
@@ -363,6 +345,8 @@ declare module '@testing-library/react-native' {
|
|
|
363
345
|
options?: RenderOptions
|
|
364
346
|
) => RenderAPI;
|
|
365
347
|
|
|
348
|
+
declare export var screen: RenderAPI;
|
|
349
|
+
|
|
366
350
|
declare export var cleanup: () => void;
|
|
367
351
|
declare export var fireEvent: FireEventAPI;
|
|
368
352
|
|
package/build/matches.js
CHANGED
|
@@ -14,7 +14,8 @@ function matches(matcher, text, normalizer = getDefaultNormalizer(), exact = tru
|
|
|
14
14
|
const normalizedText = normalizer(text);
|
|
15
15
|
|
|
16
16
|
if (typeof matcher === 'string') {
|
|
17
|
-
|
|
17
|
+
const normalizedMatcher = normalizer(matcher);
|
|
18
|
+
return exact ? normalizedText === normalizedMatcher : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase());
|
|
18
19
|
} else {
|
|
19
20
|
return matcher.test(normalizedText);
|
|
20
21
|
}
|
package/build/matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/matches.ts"],"names":["matches","matcher","text","normalizer","getDefaultNormalizer","exact","normalizedText","toLowerCase","includes","test","trim","collapseWhitespace","replace"],"mappings":";;;;;;;;AAGO,SAASA,OAAT,CACLC,OADK,EAELC,IAFK,EAGLC,UAAwB,GAAGC,oBAAoB,EAH1C,EAILC,KAAc,GAAG,IAJZ,EAKI;AACT,MAAI,OAAOH,IAAP,KAAgB,QAApB,EAA8B;AAC5B,WAAO,KAAP;AACD;;AAED,QAAMI,cAAc,GAAGH,UAAU,CAACD,IAAD,CAAjC;;AACA,MAAI,OAAOD,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAOI,KAAK,GACRC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/matches.ts"],"names":["matches","matcher","text","normalizer","getDefaultNormalizer","exact","normalizedText","normalizedMatcher","toLowerCase","includes","test","trim","collapseWhitespace","replace"],"mappings":";;;;;;;;AAGO,SAASA,OAAT,CACLC,OADK,EAELC,IAFK,EAGLC,UAAwB,GAAGC,oBAAoB,EAH1C,EAILC,KAAc,GAAG,IAJZ,EAKI;AACT,MAAI,OAAOH,IAAP,KAAgB,QAApB,EAA8B;AAC5B,WAAO,KAAP;AACD;;AAED,QAAMI,cAAc,GAAGH,UAAU,CAACD,IAAD,CAAjC;;AACA,MAAI,OAAOD,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,UAAMM,iBAAiB,GAAGJ,UAAU,CAACF,OAAD,CAApC;AACA,WAAOI,KAAK,GACRC,cAAc,KAAKC,iBADX,GAERD,cAAc,CAACE,WAAf,GAA6BC,QAA7B,CAAsCF,iBAAiB,CAACC,WAAlB,EAAtC,CAFJ;AAGD,GALD,MAKO;AACL,WAAOP,OAAO,CAACS,IAAR,CAAaJ,cAAb,CAAP;AACD;AACF;;AAOM,SAASF,oBAAT,CAA8B;AACnCO,EAAAA,IAAI,GAAG,IAD4B;AAEnCC,EAAAA,kBAAkB,GAAG;AAFc,IAGf,EAHf,EAGiC;AACtC,SAAQV,IAAD,IAAkB;AACvB,QAAII,cAAc,GAAGJ,IAArB;AACAI,IAAAA,cAAc,GAAGK,IAAI,GAAGL,cAAc,CAACK,IAAf,EAAH,GAA2BL,cAAhD;AACAA,IAAAA,cAAc,GAAGM,kBAAkB,GAC/BN,cAAc,CAACO,OAAf,CAAuB,MAAvB,EAA+B,GAA/B,CAD+B,GAE/BP,cAFJ;AAGA,WAAOA,cAAP;AACD,GAPD;AAQD","sourcesContent":["export type NormalizerFn = (textToNormalize: string) => string;\nexport type TextMatch = string | RegExp;\n\nexport function matches(\n matcher: TextMatch,\n text: string,\n normalizer: NormalizerFn = getDefaultNormalizer(),\n exact: boolean = true\n): boolean {\n if (typeof text !== 'string') {\n return false;\n }\n\n const normalizedText = normalizer(text);\n if (typeof matcher === 'string') {\n const normalizedMatcher = normalizer(matcher);\n return exact\n ? normalizedText === normalizedMatcher\n : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase());\n } else {\n return matcher.test(normalizedText);\n }\n}\n\ntype NormalizerConfig = {\n trim?: boolean;\n collapseWhitespace?: boolean;\n};\n\nexport function getDefaultNormalizer({\n trim = true,\n collapseWhitespace = true,\n}: NormalizerConfig = {}): NormalizerFn {\n return (text: string) => {\n let normalizedText = text;\n normalizedText = trim ? normalizedText.trim() : normalizedText;\n normalizedText = collapseWhitespace\n ? normalizedText.replace(/\\s+/g, ' ')\n : normalizedText;\n return normalizedText;\n };\n}\n"],"file":"matches.js"}
|
package/build/pure.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import act from './act';
|
|
2
2
|
import cleanup from './cleanup';
|
|
3
3
|
import fireEvent from './fireEvent';
|
|
4
|
-
import render from './render';
|
|
4
|
+
import render, { RenderResult } from './render';
|
|
5
5
|
import waitFor from './waitFor';
|
|
6
6
|
import waitForElementToBeRemoved from './waitForElementToBeRemoved';
|
|
7
7
|
import { within, getQueriesForElement } from './within';
|
|
8
8
|
import { getDefaultNormalizer } from './matches';
|
|
9
9
|
import { renderHook } from './renderHook';
|
|
10
|
+
import { screen } from './screen';
|
|
11
|
+
export type { RenderResult };
|
|
12
|
+
export declare type RenderAPI = RenderResult;
|
|
10
13
|
export { act };
|
|
11
14
|
export { cleanup };
|
|
12
15
|
export { fireEvent };
|
|
@@ -16,4 +19,4 @@ export { waitForElementToBeRemoved };
|
|
|
16
19
|
export { within, getQueriesForElement };
|
|
17
20
|
export { getDefaultNormalizer };
|
|
18
21
|
export { renderHook };
|
|
19
|
-
export
|
|
22
|
+
export { screen };
|
package/build/pure.js
CHANGED
|
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "renderHook", {
|
|
|
45
45
|
return _renderHook.renderHook;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "screen", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _screen.screen;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
48
54
|
Object.defineProperty(exports, "waitFor", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function () {
|
|
@@ -82,5 +88,7 @@ var _matches = require("./matches");
|
|
|
82
88
|
|
|
83
89
|
var _renderHook = require("./renderHook");
|
|
84
90
|
|
|
91
|
+
var _screen = require("./screen");
|
|
92
|
+
|
|
85
93
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
86
94
|
//# sourceMappingURL=pure.js.map
|
package/build/pure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/pure.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["import act from './act';\nimport cleanup from './cleanup';\nimport fireEvent from './fireEvent';\nimport render, { RenderResult } from './render';\nimport waitFor from './waitFor';\nimport waitForElementToBeRemoved from './waitForElementToBeRemoved';\nimport { within, getQueriesForElement } from './within';\nimport { getDefaultNormalizer } from './matches';\nimport { renderHook } from './renderHook';\nimport { screen } from './screen';\n\nexport type { RenderResult };\nexport type RenderAPI = RenderResult;\n\nexport { act };\nexport { cleanup };\nexport { fireEvent };\nexport { render };\nexport { waitFor };\nexport { waitForElementToBeRemoved };\nexport { within, getQueriesForElement };\nexport { getDefaultNormalizer };\nexport { renderHook };\nexport { screen };\n"],"file":"pure.js"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import { AccessibilityState } from 'react-native';
|
|
3
|
+
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
+
export declare type ByA11yStateQueries = {
|
|
5
|
+
getByA11yState: GetByQuery<AccessibilityState>;
|
|
6
|
+
getAllByA11yState: GetAllByQuery<AccessibilityState>;
|
|
7
|
+
queryByA11yState: QueryByQuery<AccessibilityState>;
|
|
8
|
+
queryAllByA11yState: QueryAllByQuery<AccessibilityState>;
|
|
9
|
+
findByA11yState: FindByQuery<AccessibilityState>;
|
|
10
|
+
findAllByA11yState: FindAllByQuery<AccessibilityState>;
|
|
11
|
+
getByAccessibilityState: GetByQuery<AccessibilityState>;
|
|
12
|
+
getAllByAccessibilityState: GetAllByQuery<AccessibilityState>;
|
|
13
|
+
queryByAccessibilityState: QueryByQuery<AccessibilityState>;
|
|
14
|
+
queryAllByAccessibilityState: QueryAllByQuery<AccessibilityState>;
|
|
15
|
+
findByAccessibilityState: FindByQuery<AccessibilityState>;
|
|
16
|
+
findAllByAccessibilityState: FindAllByQuery<AccessibilityState>;
|
|
17
|
+
};
|
|
18
|
+
export declare const bindByA11yStateQueries: (instance: ReactTestInstance) => ByA11yStateQueries;
|