@testing-library/react-native 11.4.0 → 11.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +3 -3
  2. package/build/act.d.ts +3 -1
  3. package/build/act.js +1 -13
  4. package/build/act.js.map +1 -1
  5. package/build/cleanup.d.ts +1 -1
  6. package/build/config.d.ts +31 -2
  7. package/build/config.js +28 -3
  8. package/build/config.js.map +1 -1
  9. package/build/fireEvent.js +3 -3
  10. package/build/fireEvent.js.map +1 -1
  11. package/build/flushMicroTasks.d.ts +1 -1
  12. package/build/helpers/accessiblity.d.ts +11 -4
  13. package/build/helpers/accessiblity.js +29 -9
  14. package/build/helpers/accessiblity.js.map +1 -1
  15. package/build/helpers/debugDeep.d.ts +1 -1
  16. package/build/helpers/findAll.d.ts +10 -0
  17. package/build/helpers/findAll.js +44 -0
  18. package/build/helpers/findAll.js.map +1 -0
  19. package/build/helpers/format.d.ts +2 -2
  20. package/build/helpers/getTextContent.d.ts +2 -0
  21. package/build/helpers/getTextContent.js +20 -0
  22. package/build/helpers/getTextContent.js.map +1 -0
  23. package/build/helpers/host-component-names.d.ts +2 -0
  24. package/build/helpers/host-component-names.js +50 -0
  25. package/build/helpers/host-component-names.js.map +1 -0
  26. package/build/helpers/matchers/accessibilityValue.d.ts +9 -0
  27. package/build/helpers/matchers/accessibilityValue.js +12 -0
  28. package/build/helpers/matchers/accessibilityValue.js.map +1 -0
  29. package/build/helpers/matchers/matchLabelText.d.ts +3 -0
  30. package/build/helpers/matchers/matchLabelText.js +26 -0
  31. package/build/helpers/matchers/matchLabelText.js.map +1 -0
  32. package/build/helpers/matchers/matchTextContent.d.ts +10 -0
  33. package/build/helpers/matchers/matchTextContent.js +24 -0
  34. package/build/helpers/matchers/matchTextContent.js.map +1 -0
  35. package/build/helpers/timers.d.ts +0 -2
  36. package/build/helpers/timers.js.map +1 -1
  37. package/build/index.flow.js +123 -54
  38. package/build/matches.d.ts +7 -3
  39. package/build/matches.js.map +1 -1
  40. package/build/pure.d.ts +12 -23
  41. package/build/pure.js +8 -2
  42. package/build/pure.js.map +1 -1
  43. package/build/queries/a11yState.d.ts +15 -14
  44. package/build/queries/a11yState.js +3 -2
  45. package/build/queries/a11yState.js.map +1 -1
  46. package/build/queries/a11yValue.d.ts +15 -20
  47. package/build/queries/a11yValue.js +16 -5
  48. package/build/queries/a11yValue.js.map +1 -1
  49. package/build/queries/displayValue.d.ts +11 -9
  50. package/build/queries/displayValue.js +7 -2
  51. package/build/queries/displayValue.js.map +1 -1
  52. package/build/queries/hintText.d.ts +23 -21
  53. package/build/queries/hintText.js +2 -1
  54. package/build/queries/hintText.js.map +1 -1
  55. package/build/queries/labelText.d.ts +11 -9
  56. package/build/queries/labelText.js +7 -11
  57. package/build/queries/labelText.js.map +1 -1
  58. package/build/queries/makeQueries.d.ts +8 -8
  59. package/build/queries/options.d.ts +11 -0
  60. package/build/queries/options.js +2 -0
  61. package/build/queries/options.js.map +1 -0
  62. package/build/queries/placeholderText.d.ts +11 -9
  63. package/build/queries/placeholderText.js +8 -3
  64. package/build/queries/placeholderText.js.map +1 -1
  65. package/build/queries/role.d.ts +7 -4
  66. package/build/queries/role.js +22 -11
  67. package/build/queries/role.js.map +1 -1
  68. package/build/queries/testId.d.ts +11 -9
  69. package/build/queries/testId.js +2 -2
  70. package/build/queries/testId.js.map +1 -1
  71. package/build/queries/text.d.ts +11 -13
  72. package/build/queries/text.js +24 -51
  73. package/build/queries/text.js.map +1 -1
  74. package/build/queries/unsafeProps.d.ts +1 -1
  75. package/build/queries/unsafeType.d.ts +1 -1
  76. package/build/render.d.ts +92 -146
  77. package/build/renderHook.d.ts +2 -2
  78. package/build/waitFor.d.ts +1 -1
  79. package/build/within.d.ts +90 -144
  80. package/package.json +17 -18
  81. package/typings/index.flow.js +123 -54
@@ -5,9 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.bindByRoleQueries = void 0;
7
7
  var _accessiblity = require("../helpers/accessiblity");
8
+ var _findAll = require("../helpers/findAll");
8
9
  var _accessibilityState = require("../helpers/matchers/accessibilityState");
10
+ var _accessibilityValue = require("../helpers/matchers/accessibilityValue");
9
11
  var _matchStringProp = require("../helpers/matchers/matchStringProp");
10
12
  var _within = require("../within");
13
+ var _config = require("../config");
11
14
  var _makeQueries = require("./makeQueries");
12
15
  const matchAccessibleNameIfNeeded = (node, name) => {
13
16
  if (name == null) return true;
@@ -20,26 +23,34 @@ const matchAccessibleNameIfNeeded = (node, name) => {
20
23
  const matchAccessibleStateIfNeeded = (node, options) => {
21
24
  return options != null ? (0, _accessibilityState.matchAccessibilityState)(node, options) : true;
22
25
  };
26
+ const matchAccessibilityValueIfNeeded = (node, value) => {
27
+ return value != null ? (0, _accessibilityValue.matchAccessibilityValue)(node, value) : true;
28
+ };
23
29
  const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
24
- return instance.findAll(node =>
25
- // run the cheapest checks first, and early exit too avoid unneeded computations
26
-
27
- typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibleNameIfNeeded(node, options?.name));
30
+ const shouldMatchOnlyAccessibilityElements = (0, _config.getConfig)().useBreakingChanges;
31
+ return (0, _findAll.findAll)(instance, node =>
32
+ // run the cheapest checks first, and early exit to avoid unneeded computations
33
+ typeof node.type === 'string' && (!shouldMatchOnlyAccessibilityElements || (0, _accessiblity.isAccessibilityElement)(node)) && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibilityValueIfNeeded(node, options?.value) && matchAccessibleNameIfNeeded(node, options?.name), options);
28
34
  };
29
- const buildErrorMessage = (role, options = {}) => {
30
- const errors = [`role: "${String(role)}"`];
35
+ const formatQueryParams = (role, options = {}) => {
36
+ const params = [`role: "${String(role)}"`];
31
37
  if (options.name) {
32
- errors.push(`name: "${String(options.name)}"`);
38
+ params.push(`name: "${String(options.name)}"`);
33
39
  }
34
40
  _accessiblity.accessibilityStateKeys.forEach(stateKey => {
35
41
  if (options[stateKey] !== undefined) {
36
- errors.push(`${stateKey} state: ${options[stateKey]}`);
42
+ params.push(`${stateKey} state: ${options[stateKey]}`);
43
+ }
44
+ });
45
+ _accessiblity.accessiblityValueKeys.forEach(valueKey => {
46
+ if (options?.value?.[valueKey] !== undefined) {
47
+ params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);
37
48
  }
38
49
  });
39
- return errors.join(', ');
50
+ return params.join(', ');
40
51
  };
41
- const getMultipleError = (role, options) => `Found multiple elements with ${buildErrorMessage(role, options)}`;
42
- const getMissingError = (role, options) => `Unable to find an element with ${buildErrorMessage(role, options)}`;
52
+ const getMultipleError = (role, options) => `Found multiple elements with ${formatQueryParams(role, options)}`;
53
+ const getMissingError = (role, options) => `Unable to find an element with ${formatQueryParams(role, options)}`;
43
54
  const {
44
55
  getBy,
45
56
  getAllBy,
@@ -1 +1 @@
1
- {"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","queryAllByRole","instance","queryAllByRoleFn","role","findAll","type","matchStringProp","props","accessibilityRole","buildErrorMessage","errors","String","push","accessibilityStateKeys","forEach","stateKey","undefined","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import { type AccessibilityState } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { accessibilityStateKeys } from '../helpers/accessiblity';\nimport { matchAccessibilityState } from '../helpers/matchers/accessibilityState';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport type { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\ntype ByRoleOptions = {\n name?: TextMatch;\n} & AccessibilityState;\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst matchAccessibleStateIfNeeded = (\n node: ReactTestInstance,\n options?: ByRoleOptions\n) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n return instance.findAll(\n (node) =>\n // run the cheapest checks first, and early exit too avoid unneeded computations\n\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibleNameIfNeeded(node, options?.name)\n );\n };\n\nconst buildErrorMessage = (role: TextMatch, options: ByRoleOptions = {}) => {\n const errors = [`role: \"${String(role)}\"`];\n\n if (options.name) {\n errors.push(`name: \"${String(options.name)}\"`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n errors.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n return errors.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${buildErrorMessage(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${buildErrorMessage(role, options)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAEA;AACA;AAcA,MAAMA,2BAA2B,GAAG,CAClCC,IAAuB,EACvBC,IAAgB,KACb;EACH,IAAIA,IAAI,IAAI,IAAI,EAAE,OAAO,IAAI;EAE7B,MAAM;IAAEC,cAAc;IAAEC;EAAoB,CAAC,GAAG,IAAAC,4BAAoB,EAACJ,IAAI,CAAC;EAC1E,OACEE,cAAc,CAACD,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC,IAAIF,mBAAmB,CAACF,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC;AAE3E,CAAC;AAED,MAAMC,4BAA4B,GAAG,CACnCN,IAAuB,EACvBO,OAAuB,KACpB;EACH,OAAOA,OAAO,IAAI,IAAI,GAAG,IAAAC,2CAAuB,EAACR,IAAI,EAAEO,OAAO,CAAC,GAAG,IAAI;AACxE,CAAC;AAED,MAAME,cAAc,GAClBC,QAA2B,IAE3B,SAASC,gBAAgB,CAACC,IAAI,EAAEL,OAAO,EAAE;EACvC,OAAOG,QAAQ,CAACG,OAAO,CACpBb,IAAI;EACH;;EAEA,OAAOA,IAAI,CAACc,IAAI,KAAK,QAAQ,IAC7B,IAAAC,gCAAe,EAACf,IAAI,CAACgB,KAAK,CAACC,iBAAiB,EAAEL,IAAI,CAAC,IACnDN,4BAA4B,CAACN,IAAI,EAAEO,OAAO,CAAC,IAC3CR,2BAA2B,CAACC,IA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AAEuB,UAAU,CAACtB,QAAQ,CAAC;EACpC8B,UAAU,EAAEP,MAAM,CAACvB,QAAQ,CAAC;EAC5B+B,aAAa,EAAEP,SAAS,CAACxB,QAAQ;AACnC,CAAC,CAAC;AAAC"}
1
+ {"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","instance","queryAllByRoleFn","role","shouldMatchOnlyAccessibilityElements","getConfig","useBreakingChanges","findAll","type","isAccessibilityElement","matchStringProp","props","accessibilityRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessiblityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { AccessibilityState } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport {\n accessibilityStateKeys,\n accessiblityValueKeys,\n isAccessibilityElement,\n} from '../helpers/accessiblity';\nimport { findAll } from '../helpers/findAll';\nimport { matchAccessibilityState } from '../helpers/matchers/accessibilityState';\nimport {\n AccessibilityValueMatcher,\n matchAccessibilityValue,\n} from '../helpers/matchers/accessibilityValue';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport type { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { getConfig } from '../config';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport { CommonQueryOptions } from './options';\n\ntype ByRoleOptions = CommonQueryOptions &\n AccessibilityState & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst matchAccessibleStateIfNeeded = (\n node: ReactTestInstance,\n options?: ByRoleOptions\n) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (\n node: ReactTestInstance,\n value?: AccessibilityValueMatcher\n) => {\n return value != null ? matchAccessibilityValue(node, value) : true;\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n const shouldMatchOnlyAccessibilityElements = getConfig().useBreakingChanges;\n\n return findAll(\n instance,\n (node) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n typeof node.type === 'string' &&\n (!shouldMatchOnlyAccessibilityElements ||\n isAccessibilityElement(node)) &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibilityValueIfNeeded(node, options?.value) &&\n matchAccessibleNameIfNeeded(node, options?.name),\n options\n );\n };\n\nconst formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {\n const params = [`role: \"${String(role)}\"`];\n\n if (options.name) {\n params.push(`name: \"${String(options.name)}\"`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n params.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n accessiblityValueKeys.forEach((valueKey) => {\n if (options?.value?.[valueKey] !== undefined) {\n params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);\n }\n });\n\n return params.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${formatQueryParams(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${formatQueryParams(role, options)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":";;;;;;AAEA;AAKA;AACA;AACA;AAIA;AAEA;AACA;AACA;AAiBA,MAAMA,2BAA2B,GAAG,CAClCC,IAAuB,EACvBC,IAAgB,KACb;EACH,IAAIA,IAAI,IAAI,IAAI,EAAE,OAAO,IAAI;EAE7B,MAAM;IAAEC,cAAc;IAAEC;EAAoB,CAAC,GAAG,IAAAC,4BAAoB,EAACJ,IAAI,CAAC;EAC1E,OACEE,cAAc,CAACD,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC,IAAIF,mBAAmB,CAACF,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC;AAE3E,CAAC;AAED,MAAMC,4BAA4B,GAAG,CACnCN,IAAuB,EACvBO,OAAuB,KACpB;EACH,OAAOA,OAAO,IAAI,IAAI,GAAG,IAAAC,2CAAuB,EAACR,IAAI,EAAEO,OAAO,CAAC,GAAG,IAAI;AACxE,CAAC;AAED,MAAME,+BAA+B,GAAG,CACtCT,IAAuB,EACvBU,KAAiC,KAC9B;EACH,OAAOA,KAAK,IAAI,IAAI,GAAG,IAAAC,2CAAuB,EAACX,IAAI,EAAEU,KAAK,CAAC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CAAC,KAAKF,SAAS,EAAE;MAC5CN,MAAM,CAACE,IAAI,CAAE,GAAEM,QAAS,WAAU3B,OAAO,EAAEG,KAAK,GAAGwB,QAAQ,CAAE,EAAC,CAAC;IACjE;EACF,CAAC,CAAC;EAEF,OAAOR,MAAM,CAACS,IAAI,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED,MAAMC,gBAAgB,GAAG,CAACrB,IAAe,EAAER,OAAuB,KAC/D,gCAA+BkB,iBAAiB,CAACV,IAAI,EAAER,OAAO,CAAE,EAAC;AAEpE,MAAM8B,eAAe,GAAG,CAACtB,IAAe,EAAER,OAAuB,KAC9D,kCAAiCkB,iBAAiB,CAACV,IAAI,EAAER,OAAO,CAAE,EAAC;AAEtE,MAAM;EAAE+B,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EhC,cAAc,EACdyB,eAAe,EACfD,gBAAgB,CACjB;AAWM,MAAMS,iBAAiB,GAC5BhC,QAA2B,KACR;EACnBiC,SAAS,EAAER,KAAK,CAACzB,QAAQ,CAAC;EAC1BkC,YAAY,EAAER,QAAQ,CAAC1B,QAAQ,CAAC;EAChCmC,WAAW,EAAER,OAAO,CAAC3B,QAAQ,CAAC;EAC9BD,cAAc,EAAE6B,UAAU,CAAC5B,QAAQ,CAAC;EACpCoC,UAAU,EAAEP,MAAM,CAAC7B,QAAQ,CAAC;EAC5BqC,aAAa,EAAEP,SAAS,CAAC9B,QAAQ;AACnC,CAAC,CAAC;AAAC"}
@@ -1,13 +1,15 @@
1
1
  import type { ReactTestInstance } from 'react-test-renderer';
2
- import { TextMatch } from '../matches';
2
+ import { TextMatch, TextMatchOptions } from '../matches';
3
3
  import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
4
- import type { TextMatchOptions } from './text';
5
- export declare type ByTestIdQueries = {
6
- getByTestId: GetByQuery<TextMatch, TextMatchOptions>;
7
- getAllByTestId: GetAllByQuery<TextMatch, TextMatchOptions>;
8
- queryByTestId: QueryByQuery<TextMatch, TextMatchOptions>;
9
- queryAllByTestId: QueryAllByQuery<TextMatch, TextMatchOptions>;
10
- findByTestId: FindByQuery<TextMatch, TextMatchOptions>;
11
- findAllByTestId: FindAllByQuery<TextMatch, TextMatchOptions>;
4
+ import type { CommonQueryOptions } from './options';
5
+ type ByTestIdOptions = CommonQueryOptions & TextMatchOptions;
6
+ export type ByTestIdQueries = {
7
+ getByTestId: GetByQuery<TextMatch, ByTestIdOptions>;
8
+ getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;
9
+ queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;
10
+ queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;
11
+ findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;
12
+ findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;
12
13
  };
13
14
  export declare const bindByTestIdQueries: (instance: ReactTestInstance) => ByTestIdQueries;
15
+ export {};
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindByTestIdQueries = void 0;
7
+ var _findAll = require("../helpers/findAll");
7
8
  var _matches = require("../matches");
8
9
  var _makeQueries = require("./makeQueries");
9
10
  const getNodeByTestId = (node, testID, options = {}) => {
@@ -14,8 +15,7 @@ const getNodeByTestId = (node, testID, options = {}) => {
14
15
  return (0, _matches.matches)(testID, node.props.testID, normalizer, exact);
15
16
  };
16
17
  const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
17
- const results = instance.findAll(node => getNodeByTestId(node, testId, queryOptions)).filter(element => typeof element.type === 'string');
18
- return results;
18
+ return (0, _findAll.findAll)(instance, node => typeof node.type === 'string' && getNodeByTestId(node, testId, queryOptions), queryOptions);
19
19
  };
20
20
  const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
21
21
  const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
@@ -1 +1 @@
1
- {"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { TextMatchOptions } from './text';\n\nconst getNodeByTestId = (\n node: ReactTestInstance,\n testID: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return matches(testID, node.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (\n instance: ReactTestInstance\n): ((\n testId: TextMatch,\n queryOptions?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTestIdFn(testId, queryOptions) {\n const results = instance\n .findAll((node) => getNodeByTestId(node, testId, queryOptions))\n .filter((element) => typeof element.type === 'string');\n\n return results;\n };\n\nconst getMultipleError = (testId: TextMatch) =>\n `Found multiple elements with testID: ${String(testId)}`;\nconst getMissingError = (testId: TextMatch) =>\n `Unable to find an element with testID: ${String(testId)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByTestId,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTestIdQueries = {\n getByTestId: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByTestId: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByTestId: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByTestIdQueries = (\n instance: ReactTestInstance\n): ByTestIdQueries => ({\n getByTestId: getBy(instance),\n getAllByTestId: getAllBy(instance),\n queryByTestId: queryBy(instance),\n queryAllByTestId: queryAllBy(instance),\n findByTestId: findBy(instance),\n findAllByTestId: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AAWA,MAAMA,eAAe,GAAG,CACtBC,IAAuB,EACvBC,MAAiB,EACjBC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OAAO,IAAAG,gBAAO,EAACJ,MAAM,EAAED,IAAI,CAACM,KAAK,CAACL,MAAM,EAAEG,UAAU,EAAED,KAAK,CAAC;AAC9D,CAAC;AAED,MAAMI,gBAAgB,GACpBC,QAA2B,IAK3B,SAASC,kBAAkB,CAACC,MAAM,EAAEC,YAAY,EAAE;EAChD,MAAMC,OAAO,GAAGJ,QAAQ,CACrBK,OAAO,CAAEb,IAAI,IAAKD,eAAe,CAACC,IAAI,EAAEU,MAAM,EAAEC,YAAY,CAAC,CAAC,CAC9DG,MAAM,CAAEC,OAAO,IAAK,OAAOA,OAAO,CAACC,IAAI,KAAK,QAAQ,CAAC;EAExD,OAAOJ,OAAO;AAChB,CAAC;AAEH,MAAMK,gBAAgB,GAAIP,MAAiB,IACxC,wCAAuCQ,MAAM,CAACR,MAAM,CAAE,EAAC;AAC1D,MAAMS,eAAe,GAAIT,MAAiB,IACvC,0CAAyCQ,MAAM,CAACR,MAAM,CAAE,EAAC;AAE5D,MAAM;EAAEU,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EnB,gBAAgB,EAChBY,eAAe,EACfF,gBAAgB,CACjB;AAWM,MAAMU,mBAAmB,GAC9BnB,QAA2B,KACN;EACrBoB,WAAW,EAAER,KAAK,CAACZ,QAAQ,CAAC;EAC5BqB,cAAc,EAAER,QAAQ,CAACb,QAAQ,CAAC;EAClCsB,aAAa,EAAER,OAAO,CAACd,QAAQ,CAAC;EAChCD,gBAAgB,EAAEgB,UAAU,CAACf,QAAQ,CAAC;EACtCuB,YAAY,EAAEP,MAAM,CAAChB,QAAQ,CAAC;EAC9BwB,eAAe,EAAEP,SAAS,CAACjB,QAAQ;AACrC,CAAC,CAAC;AAAC"}
1
+ {"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","findAll","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { findAll } from '../helpers/findAll';\nimport { matches, TextMatch, TextMatchOptions } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTestIdOptions = CommonQueryOptions & TextMatchOptions;\n\nconst getNodeByTestId = (\n node: ReactTestInstance,\n testID: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return matches(testID, node.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (\n instance: ReactTestInstance\n): ((\n testId: TextMatch,\n queryOptions?: ByTestIdOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTestIdFn(testId, queryOptions) {\n return findAll(\n instance,\n (node) =>\n typeof node.type === 'string' &&\n getNodeByTestId(node, testId, queryOptions),\n queryOptions\n );\n };\n\nconst getMultipleError = (testId: TextMatch) =>\n `Found multiple elements with testID: ${String(testId)}`;\nconst getMissingError = (testId: TextMatch) =>\n `Unable to find an element with testID: ${String(testId)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByTestId,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTestIdQueries = {\n getByTestId: GetByQuery<TextMatch, ByTestIdOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;\n queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;\n findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;\n};\n\nexport const bindByTestIdQueries = (\n instance: ReactTestInstance\n): ByTestIdQueries => ({\n getByTestId: getBy(instance),\n getAllByTestId: getAllBy(instance),\n queryByTestId: queryBy(instance),\n queryAllByTestId: queryAllBy(instance),\n findByTestId: findBy(instance),\n findAllByTestId: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AAaA,MAAMA,eAAe,GAAG,CACtBC,IAAuB,EACvBC,MAAiB,EACjBC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OAAO,IAAAG,gBAAO,EAACJ,MAAM,EAAED,IAAI,CAACM,KAAK,CAACL,MAAM,EAAEG,UAAU,EAAED,KAAK,CAAC;AAC9D,CAAC;AAED,MAAMI,gBAAgB,GACpBC,QAA2B,IAK3B,SAASC,kBAAkB,CAACC,MAAM,EAAEC,YAAY,EAAE;EAChD,OAAO,IAAAC,gBAAO,EACZJ,QAAQ,EACPR,IAAI,IACH,OAAOA,IAAI,CAACa,IAAI,KAAK,QAAQ,IAC7Bd,eAAe,CAACC,IAAI,EAAEU,MAAM,EAAEC,YAAY,CAAC,EAC7CA,YAAY,CACb;AACH,CAAC;AAEH,MAAMG,gBAAgB,GAAIJ,MAAiB,IACxC,wCAAuCK,MAAM,CAACL,MAAM,CAAE,EAAC;AAC1D,MAAMM,eAAe,GAAIN,MAAiB,IACvC,0CAAyCK,MAAM,CAACL,MAAM,CAAE,EAAC;AAE5D,MAAM;EAAEO,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EhB,gBAAgB,EAChBS,eAAe,EACfF,gBAAgB,CACjB;AAWM,MAAMU,mBAAmB,GAC9BhB,QAA2B,KACN;EACrBiB,WAAW,EAAER,KAAK,CAACT,QAAQ,CAAC;EAC5BkB,cAAc,EAAER,QAAQ,CAACV,QAAQ,CAAC;EAClCmB,aAAa,EAAER,OAAO,CAACX,QAAQ,CAAC;EAChCD,gBAAgB,EAAEa,UAAU,CAACZ,QAAQ,CAAC;EACtCoB,YAAY,EAAEP,MAAM,CAACb,QAAQ,CAAC;EAC9BqB,eAAe,EAAEP,SAAS,CAACd,QAAQ;AACrC,CAAC,CAAC;AAAC"}
@@ -1,17 +1,15 @@
1
1
  import type { ReactTestInstance } from 'react-test-renderer';
2
- import { TextMatch } from '../matches';
3
- import type { NormalizerFn } from '../matches';
2
+ import { TextMatch, TextMatchOptions } from '../matches';
4
3
  import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
5
- export declare type TextMatchOptions = {
6
- exact?: boolean;
7
- normalizer?: NormalizerFn;
8
- };
9
- export declare type ByTextQueries = {
10
- getByText: GetByQuery<TextMatch, TextMatchOptions>;
11
- getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;
12
- queryByText: QueryByQuery<TextMatch, TextMatchOptions>;
13
- queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;
14
- findByText: FindByQuery<TextMatch, TextMatchOptions>;
15
- findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;
4
+ import type { CommonQueryOptions } from './options';
5
+ type ByTextOptions = CommonQueryOptions & TextMatchOptions;
6
+ export type ByTextQueries = {
7
+ getByText: GetByQuery<TextMatch, ByTextOptions>;
8
+ getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;
9
+ queryByText: QueryByQuery<TextMatch, ByTextOptions>;
10
+ queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;
11
+ findByText: FindByQuery<TextMatch, ByTextOptions>;
12
+ findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;
16
13
  };
17
14
  export declare const bindByTextQueries: (instance: ReactTestInstance) => ByTextQueries;
15
+ export {};
@@ -5,61 +5,34 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.bindByTextQueries = void 0;
7
7
  var _reactNative = require("react-native");
8
- var React = _interopRequireWildcard(require("react"));
9
- var _filterNodeByType = require("../helpers/filterNodeByType");
8
+ var _config = require("../config");
10
9
  var _componentTree = require("../helpers/component-tree");
11
- var _matches = require("../matches");
10
+ var _filterNodeByType = require("../helpers/filterNodeByType");
11
+ var _findAll = require("../helpers/findAll");
12
+ var _hostComponentNames = require("../helpers/host-component-names");
13
+ var _matchTextContent = require("../helpers/matchers/matchTextContent");
12
14
  var _makeQueries = require("./makeQueries");
13
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
- const getChildrenAsText = children => {
16
- const textContent = [];
17
- React.Children.forEach(children, child => {
18
- if (typeof child === 'string') {
19
- textContent.push(child);
20
- return;
21
- }
22
- if (typeof child === 'number') {
23
- textContent.push(child.toString());
24
- return;
25
- }
26
- if (child?.props?.children) {
27
- // Bail on traversing text children down the tree if current node (child)
28
- // has no text. In such situations, react-test-renderer will traverse down
29
- // this tree in a separate call and run this query again. As a result, the
30
- // query will match the deepest text node that matches requested text.
31
- if ((0, _filterNodeByType.filterNodeByType)(child, _reactNative.Text)) {
32
- return;
33
- }
34
- if ((0, _filterNodeByType.filterNodeByType)(child, React.Fragment)) {
35
- textContent.push(...getChildrenAsText(child.props.children));
36
- }
37
- }
38
- });
39
- return textContent;
40
- };
41
- const getNodeByText = (node, text, options = {}) => {
42
- const isTextComponent = (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text);
43
- if (isTextComponent) {
44
- const textChildren = getChildrenAsText(node.props.children);
45
- if (textChildren) {
46
- const textToTest = textChildren.join('');
47
- const {
48
- exact,
49
- normalizer
50
- } = options;
51
- return (0, _matches.matches)(text, textToTest, normalizer, exact);
15
+ const queryAllByText = instance => function queryAllByTextFn(text, options = {}) {
16
+ const shouldReturnHostText = (0, _config.getConfig)().useBreakingChanges;
17
+
18
+ // Legacy version: return composite Text
19
+ if (!shouldReturnHostText) {
20
+ const baseInstance = (0, _componentTree.isHostElementForType)(instance, _reactNative.Text) ? (0, _componentTree.getCompositeParentOfType)(instance, _reactNative.Text) : instance;
21
+ if (!baseInstance) {
22
+ return [];
52
23
  }
24
+ const results = (0, _findAll.findAll)(baseInstance, node => (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text) && (0, _matchTextContent.matchTextContent)(node, text, options), {
25
+ ...options,
26
+ matchDeepestOnly: true
27
+ });
28
+ return results;
53
29
  }
54
- return false;
55
- };
56
- const queryAllByText = instance => function queryAllByTextFn(text, options) {
57
- const baseInstance = (0, _componentTree.isHostElementForType)(instance, _reactNative.Text) ? (0, _componentTree.getCompositeParentOfType)(instance, _reactNative.Text) : instance;
58
- if (!baseInstance) {
59
- return [];
60
- }
61
- const results = baseInstance.findAll(node => getNodeByText(node, text, options));
62
- return results;
30
+
31
+ // vNext version: returns host Text
32
+ return (0, _findAll.findAll)(instance, node => (0, _filterNodeByType.filterNodeByType)(node, (0, _hostComponentNames.getHostComponentNames)().text) && (0, _matchTextContent.matchTextContent)(node, text, options), {
33
+ ...options,
34
+ matchDeepestOnly: true
35
+ });
63
36
  };
64
37
  const getMultipleError = text => `Found multiple elements with text: ${String(text)}`;
65
38
  const getMissingError = text => `Unable to find an element with text: ${String(text)}`;
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":["getChildrenAsText","children","textContent","React","Children","forEach","child","push","toString","props","filterNodeByType","Text","Fragment","getNodeByText","node","text","options","isTextComponent","textChildren","textToTest","join","exact","normalizer","matches","queryAllByText","instance","queryAllByTextFn","baseInstance","isHostElementForType","getCompositeParentOfType","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { Text } from 'react-native';\nimport * as React from 'react';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport {\n isHostElementForType,\n getCompositeParentOfType,\n} from '../helpers/component-tree';\nimport { matches, TextMatch } from '../matches';\nimport type { NormalizerFn } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nconst getChildrenAsText = (children: React.ReactChild[]) => {\n const textContent: string[] = [];\n React.Children.forEach(children, (child) => {\n if (typeof child === 'string') {\n textContent.push(child);\n return;\n }\n\n if (typeof child === 'number') {\n textContent.push(child.toString());\n return;\n }\n\n if (child?.props?.children) {\n // Bail on traversing text children down the tree if current node (child)\n // has no text. In such situations, react-test-renderer will traverse down\n // this tree in a separate call and run this query again. As a result, the\n // query will match the deepest text node that matches requested text.\n if (filterNodeByType(child, Text)) {\n return;\n }\n\n if (filterNodeByType(child, React.Fragment)) {\n textContent.push(...getChildrenAsText(child.props.children));\n }\n }\n });\n\n return textContent;\n};\n\nconst getNodeByText = (\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const isTextComponent = filterNodeByType(node, Text);\n if (isTextComponent) {\n const textChildren = getChildrenAsText(node.props.children);\n if (textChildren) {\n const textToTest = textChildren.join('');\n const { exact, normalizer } = options;\n return matches(text, textToTest, normalizer, exact);\n }\n }\n return false;\n};\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((\n text: TextMatch,\n options?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options) {\n const baseInstance = isHostElementForType(instance, Text)\n ? getCompositeParentOfType(instance, Text)\n : instance;\n\n if (!baseInstance) {\n return [];\n }\n\n const results = baseInstance.findAll((node) =>\n getNodeByText(node, text, options)\n );\n\n return results;\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\nconst getMissingError = (text: TextMatch) =>\n `Unable to find an element with text: ${String(text)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTextQueries = {\n getByText: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByTextQueries = (\n instance: ReactTestInstance\n): ByTextQueries => ({\n getByText: getBy(instance),\n getAllByText: getAllBy(instance),\n queryByText: queryBy(instance),\n queryAllByText: queryAllBy(instance),\n findByText: findBy(instance),\n findAllByText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AAIA;AAEA;AAA4C;AAAA;AAe5C,MAAMA,iBAAiB,GAAIC,QAA4B,IAAK;EAC1D,MAAMC,WAAqB,GAAG,EAAE;EAChCC,KAAK,CAACC,QAAQ,CAACC,OAAO,CAACJ,QAAQ,EAAGK,KAAK,IAAK;IAC1C,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7BJ,WAAW,CAACK,IAAI,CAACD,KAAK,CAAC;MACvB;IACF;IAEA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7BJ,WAAW,CAACK,IAAI,CAACD,KAAK,CAACE,QAAQ,EAAE,CAAC;MAClC;IACF;IAEA,IAAIF,KAAK,EAAEG,KAAK,EAAER,QAAQ,EAAE;MAC1B;MACA;MACA;MACA;MACA,IAAI,IAAAS,kCAAgB,EAACJ,KAAK,EAAEK,iBAAI,CAAC,EAAE;QACjC;MACF;MAEA,IAAI,IAAAD,kCAAgB,EAACJ,KAAK,EAAEH,KAAK,CAACS,QAAQ,CAAC,EAAE;QAC3CV,WAAW,CAACK,IAAI,CAAC,GAAGP,iBAAiB,CAACM,KAAK,CAACG,KAAK,CAACR,QAAQ,CAAC,CAAC;MAC9D;IACF;EACF,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB,CAAC;AAED,MAAMW,aAAa,GAAG,CACpBC,IAAuB,EACvBC,IAAe,EACfC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAMC,eAA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B,QAA2B,KACR;EACnBkB,SAAS,EAAER,KAAK,CAACV,QAAQ,CAAC;EAC1BmB,YAAY,EAAER,QAAQ,CAACX,QAAQ,CAAC;EAChCoB,WAAW,EAAER,OAAO,CAACZ,QAAQ,CAAC;EAC9BD,cAAc,EAAEc,UAAU,CAACb,QAAQ,CAAC;EACpCqB,UAAU,EAAEP,MAAM,CAACd,QAAQ,CAAC;EAC5BsB,aAAa,EAAEP,SAAS,CAACf,QAAQ;AACnC,CAAC,CAAC;AAAC"}
1
+ {"version":3,"file":"text.js","names":["queryAllByText","instance","queryAllByTextFn","text","options","shouldReturnHostText","getConfig","useBreakingChanges","baseInstance","isHostElementForType","Text","getCompositeParentOfType","results","findAll","node","filterNodeByType","matchTextContent","matchDeepestOnly","getHostComponentNames","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { Text } from 'react-native';\nimport { getConfig } from '../config';\nimport {\n getCompositeParentOfType,\n isHostElementForType,\n} from '../helpers/component-tree';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { findAll } from '../helpers/findAll';\nimport { getHostComponentNames } from '../helpers/host-component-names';\nimport { matchTextContent } from '../helpers/matchers/matchTextContent';\nimport { TextMatch, TextMatchOptions } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((text: TextMatch, options?: ByTextOptions) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options = {}) {\n const shouldReturnHostText = getConfig().useBreakingChanges;\n\n // Legacy version: return composite Text\n if (!shouldReturnHostText) {\n const baseInstance = isHostElementForType(instance, Text)\n ? getCompositeParentOfType(instance, Text)\n : instance;\n\n if (!baseInstance) {\n return [];\n }\n\n const results = findAll(\n baseInstance,\n (node) =>\n filterNodeByType(node, Text) && matchTextContent(node, text, options),\n { ...options, matchDeepestOnly: true }\n );\n\n return results;\n }\n\n // vNext version: returns host Text\n return findAll(\n instance,\n (node) =>\n filterNodeByType(node, getHostComponentNames().text) &&\n matchTextContent(node, text, options),\n {\n ...options,\n matchDeepestOnly: true,\n }\n );\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\n\nconst getMissingError = (text: TextMatch) =>\n `Unable to find an element with text: ${String(text)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTextQueries = {\n getByText: GetByQuery<TextMatch, ByTextOptions>;\n getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;\n queryByText: QueryByQuery<TextMatch, ByTextOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;\n findByText: FindByQuery<TextMatch, ByTextOptions>;\n findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;\n};\n\nexport const bindByTextQueries = (\n instance: ReactTestInstance\n): ByTextQueries => ({\n getByText: getBy(instance),\n getAllByText: getAllBy(instance),\n queryByText: queryBy(instance),\n queryAllByText: queryAllBy(instance),\n findByText: findBy(instance),\n findAllByText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AAEA;AAaA,MAAMA,cAAc,GAClBC,QAA2B,IAE3B,SAASC,gBAAgB,CAACC,IAAI,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAE;EAC5C,MAAMC,oBAAoB,GAAG,IAAAC,iBAAS,GAAE,CAACC,kBAAkB;;EAE3D;EACA,IAAI,CAACF,oBAAoB,EAAE;IACzB,MAAMG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AAO,CAACvB,QAAQ,CAAC;EAC9BD,cAAc,EAAEyB,UAAU,CAACxB,QAAQ,CAAC;EACpCgC,UAAU,EAAEP,MAAM,CAACzB,QAAQ,CAAC;EAC5BiC,aAAa,EAAEP,SAAS,CAAC1B,QAAQ;AACnC,CAAC,CAAC;AAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ReactTestInstance } from 'react-test-renderer';
2
- export declare type UnsafeByPropsQueries = {
2
+ export type UnsafeByPropsQueries = {
3
3
  UNSAFE_getByProps: (props: {
4
4
  [key: string]: any;
5
5
  }) => ReactTestInstance;
@@ -1,6 +1,6 @@
1
1
  import type { ReactTestInstance } from 'react-test-renderer';
2
2
  import * as React from 'react';
3
- export declare type UnsafeByTypeQueries = {
3
+ export type UnsafeByTypeQueries = {
4
4
  UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
5
5
  UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
6
6
  UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;