@testing-library/react-native 12.2.2 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/build/config.d.ts +1 -0
  2. package/build/config.js.map +1 -1
  3. package/build/fireEvent.js +2 -1
  4. package/build/fireEvent.js.map +1 -1
  5. package/build/helpers/accessiblity.d.ts +7 -0
  6. package/build/helpers/accessiblity.js +73 -2
  7. package/build/helpers/accessiblity.js.map +1 -1
  8. package/build/helpers/component-tree.d.ts +7 -0
  9. package/build/helpers/component-tree.js +18 -0
  10. package/build/helpers/component-tree.js.map +1 -1
  11. package/build/helpers/format-default.d.ts +1 -2
  12. package/build/helpers/format-default.js +22 -13
  13. package/build/helpers/format-default.js.map +1 -1
  14. package/build/helpers/format.js +1 -4
  15. package/build/helpers/format.js.map +1 -1
  16. package/build/helpers/host-component-names.d.ts +5 -0
  17. package/build/helpers/host-component-names.js +13 -1
  18. package/build/helpers/host-component-names.js.map +1 -1
  19. package/build/helpers/matchers/accessibilityState.js +3 -3
  20. package/build/helpers/matchers/accessibilityState.js.map +1 -1
  21. package/build/helpers/matchers/accessibilityValue.js +3 -2
  22. package/build/helpers/matchers/accessibilityValue.js.map +1 -1
  23. package/build/helpers/matchers/matchLabelText.d.ts +1 -1
  24. package/build/helpers/matchers/matchLabelText.js +5 -8
  25. package/build/helpers/matchers/matchLabelText.js.map +1 -1
  26. package/build/helpers/matchers/matchTextContent.js +2 -2
  27. package/build/helpers/matchers/matchTextContent.js.map +1 -1
  28. package/build/helpers/{getTextContent.js → text-content.js} +1 -1
  29. package/build/helpers/text-content.js.map +1 -0
  30. package/build/helpers/text-input.d.ts +3 -0
  31. package/build/helpers/text-input.js +21 -0
  32. package/build/helpers/text-input.js.map +1 -0
  33. package/build/matchers/extend-expect.d.js +2 -0
  34. package/build/matchers/extend-expect.d.js.map +1 -0
  35. package/build/matchers/extend-expect.d.ts +2 -0
  36. package/build/matchers/extend-expect.js +26 -0
  37. package/build/matchers/extend-expect.js.map +1 -0
  38. package/build/matchers/index.d.ts +9 -0
  39. package/build/matchers/index.js +75 -0
  40. package/build/matchers/index.js.map +1 -0
  41. package/build/matchers/to-be-checked.d.ts +6 -0
  42. package/build/matchers/to-be-checked.js +31 -0
  43. package/build/matchers/to-be-checked.js.map +1 -0
  44. package/build/matchers/to-be-disabled.d.ts +10 -0
  45. package/build/matchers/to-be-disabled.js +52 -0
  46. package/build/matchers/to-be-disabled.js.map +1 -0
  47. package/build/matchers/to-be-empty-element.d.ts +6 -0
  48. package/build/matchers/to-be-empty-element.js +20 -0
  49. package/build/matchers/to-be-empty-element.js.map +1 -0
  50. package/build/matchers/to-be-on-the-screen.d.ts +6 -0
  51. package/build/matchers/to-be-on-the-screen.js +29 -0
  52. package/build/matchers/to-be-on-the-screen.js.map +1 -0
  53. package/build/matchers/to-be-partially-checked.d.ts +6 -0
  54. package/build/matchers/to-be-partially-checked.js +28 -0
  55. package/build/matchers/to-be-partially-checked.js.map +1 -0
  56. package/build/matchers/to-be-visible.d.ts +6 -0
  57. package/build/matchers/to-be-visible.js +56 -0
  58. package/build/matchers/to-be-visible.js.map +1 -0
  59. package/build/matchers/to-have-display-value.d.ts +7 -0
  60. package/build/matchers/to-have-display-value.js +26 -0
  61. package/build/matchers/to-have-display-value.js.map +1 -0
  62. package/build/matchers/to-have-prop.d.ts +6 -0
  63. package/build/matchers/to-have-prop.js +35 -0
  64. package/build/matchers/to-have-prop.js.map +1 -0
  65. package/build/matchers/to-have-text-content.d.ts +7 -0
  66. package/build/matchers/to-have-text-content.js +21 -0
  67. package/build/matchers/to-have-text-content.js.map +1 -0
  68. package/build/matchers/utils.d.ts +18 -0
  69. package/build/matchers/utils.js +90 -0
  70. package/build/matchers/utils.js.map +1 -0
  71. package/build/matches.d.ts +1 -1
  72. package/build/matches.js.map +1 -1
  73. package/build/queries/displayValue.js +4 -3
  74. package/build/queries/displayValue.js.map +1 -1
  75. package/build/queries/labelText.js +2 -2
  76. package/build/queries/labelText.js.map +1 -1
  77. package/build/queries/role.js +1 -1
  78. package/build/queries/role.js.map +1 -1
  79. package/build/render.d.ts +12 -48
  80. package/build/user-event/clear.js +2 -1
  81. package/build/user-event/clear.js.map +1 -1
  82. package/build/user-event/press/press.js +2 -1
  83. package/build/user-event/press/press.js.map +1 -1
  84. package/build/user-event/type/type.js +2 -1
  85. package/build/user-event/type/type.js.map +1 -1
  86. package/build/user-event/utils/index.d.ts +0 -1
  87. package/build/user-event/utils/index.js +0 -11
  88. package/build/user-event/utils/index.js.map +1 -1
  89. package/package.json +5 -21
  90. package/build/helpers/getTextContent.js.map +0 -1
  91. package/build/user-event/utils/host-components.d.ts +0 -2
  92. package/build/user-event/utils/host-components.js +0 -11
  93. package/build/user-event/utils/host-components.js.map +0 -1
  94. /package/build/helpers/{getTextContent.d.ts → text-content.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"accessibilityValue.js","names":["_matchStringProp","require","matchAccessibilityValue","node","matcher","value","props","accessibilityValue","min","undefined","max","now","text","matchStringProp"],"sources":["../../../src/helpers/matchers/accessibilityValue.ts"],"sourcesContent":["import { AccessibilityValue } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { TextMatch } from '../../matches';\nimport { matchStringProp } from './matchStringProp';\n\nexport interface AccessibilityValueMatcher {\n min?: number;\n max?: number;\n now?: number;\n text?: TextMatch;\n}\n\nexport function matchAccessibilityValue(\n node: ReactTestInstance,\n matcher: AccessibilityValueMatcher\n): boolean {\n const value: AccessibilityValue = node.props.accessibilityValue ?? {};\n return (\n (matcher.min === undefined || matcher.min === value.min) &&\n (matcher.max === undefined || matcher.max === value.max) &&\n (matcher.now === undefined || matcher.now === value.now) &&\n (matcher.text === undefined || matchStringProp(value.text, matcher.text))\n );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AASO,SAASC,uBAAuBA,CACrCC,IAAuB,EACvBC,OAAkC,EACzB;EACT,MAAMC,KAAyB,GAAGF,IAAI,CAACG,KAAK,CAACC,kBAAkB,IAAI,CAAC,CAAC;EACrE,OACE,CAACH,OAAO,CAACI,GAAG,KAAKC,SAAS,IAAIL,OAAO,CAACI,GAAG,KAAKH,KAAK,CAACG,GAAG,MACtDJ,OAAO,CAACM,GAAG,KAAKD,SAAS,IAAIL,OAAO,CAACM,GAAG,KAAKL,KAAK,CAACK,GAAG,CAAC,KACvDN,OAAO,CAACO,GAAG,KAAKF,SAAS,IAAIL,OAAO,CAACO,GAAG,KAAKN,KAAK,CAACM,GAAG,CAAC,KACvDP,OAAO,CAACQ,IAAI,KAAKH,SAAS,IAAI,IAAAI,gCAAe,EAACR,KAAK,CAACO,IAAI,EAAER,OAAO,CAACQ,IAAI,CAAC,CAAC;AAE7E"}
1
+ {"version":3,"file":"accessibilityValue.js","names":["_accessiblity","require","_matchStringProp","matchAccessibilityValue","node","matcher","value","getAccessibilityValue","min","undefined","max","now","text","matchStringProp"],"sources":["../../../src/helpers/matchers/accessibilityValue.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { getAccessibilityValue } from '../accessiblity';\nimport { TextMatch } from '../../matches';\nimport { matchStringProp } from './matchStringProp';\n\nexport interface AccessibilityValueMatcher {\n min?: number;\n max?: number;\n now?: number;\n text?: TextMatch;\n}\n\nexport function matchAccessibilityValue(\n node: ReactTestInstance,\n matcher: AccessibilityValueMatcher\n): boolean {\n const value = getAccessibilityValue(node);\n return (\n (matcher.min === undefined || matcher.min === value?.min) &&\n (matcher.max === undefined || matcher.max === value?.max) &&\n (matcher.now === undefined || matcher.now === value?.now) &&\n (matcher.text === undefined || matchStringProp(value?.text, matcher.text))\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AASO,SAASE,uBAAuBA,CACrCC,IAAuB,EACvBC,OAAkC,EACzB;EACT,MAAMC,KAAK,GAAG,IAAAC,mCAAqB,EAACH,IAAI,CAAC;EACzC,OACE,CAACC,OAAO,CAACG,GAAG,KAAKC,SAAS,IAAIJ,OAAO,CAACG,GAAG,KAAKF,KAAK,EAAEE,GAAG,MACvDH,OAAO,CAACK,GAAG,KAAKD,SAAS,IAAIJ,OAAO,CAACK,GAAG,KAAKJ,KAAK,EAAEI,GAAG,CAAC,KACxDL,OAAO,CAACM,GAAG,KAAKF,SAAS,IAAIJ,OAAO,CAACM,GAAG,KAAKL,KAAK,EAAEK,GAAG,CAAC,KACxDN,OAAO,CAACO,IAAI,KAAKH,SAAS,IAAI,IAAAI,gCAAe,EAACP,KAAK,EAAEM,IAAI,EAAEP,OAAO,CAACO,IAAI,CAAC,CAAC;AAE9E"}
@@ -1,3 +1,3 @@
1
1
  import { ReactTestInstance } from 'react-test-renderer';
2
2
  import { TextMatch, TextMatchOptions } from '../../matches';
3
- export declare function matchLabelText(root: ReactTestInstance, element: ReactTestInstance, text: TextMatch, options?: TextMatchOptions): boolean;
3
+ export declare function matchLabelText(root: ReactTestInstance, element: ReactTestInstance, expectedText: TextMatch, options?: TextMatchOptions): boolean;
@@ -5,17 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.matchLabelText = matchLabelText;
7
7
  var _matches = require("../../matches");
8
+ var _accessiblity = require("../accessiblity");
8
9
  var _findAll = require("../findAll");
9
10
  var _matchTextContent = require("./matchTextContent");
10
- function matchLabelText(root, element, text, options = {}) {
11
- return matchAccessibilityLabel(element, text, options) || matchAccessibilityLabelledBy(root, element.props.accessibilityLabelledBy, text, options);
11
+ function matchLabelText(root, element, expectedText, options = {}) {
12
+ return matchAccessibilityLabel(element, expectedText, options) || matchAccessibilityLabelledBy(root, (0, _accessiblity.getAccessibilityLabelledBy)(element), expectedText, options);
12
13
  }
13
- function matchAccessibilityLabel(element, text, options) {
14
- const {
15
- exact,
16
- normalizer
17
- } = options;
18
- return (0, _matches.matches)(text, element.props.accessibilityLabel, normalizer, exact);
14
+ function matchAccessibilityLabel(element, extpectedLabel, options) {
15
+ return (0, _matches.matches)(extpectedLabel, (0, _accessiblity.getAccessibilityLabel)(element), options.normalizer, options.exact);
19
16
  }
20
17
  function matchAccessibilityLabelledBy(root, nativeId, text, options) {
21
18
  if (!nativeId) {
@@ -1 +1 @@
1
- {"version":3,"file":"matchLabelText.js","names":["_matches","require","_findAll","_matchTextContent","matchLabelText","root","element","text","options","matchAccessibilityLabel","matchAccessibilityLabelledBy","props","accessibilityLabelledBy","exact","normalizer","matches","accessibilityLabel","nativeId","findAll","node","nativeID","matchTextContent","length"],"sources":["../../../src/helpers/matchers/matchLabelText.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch, TextMatchOptions } from '../../matches';\nimport { findAll } from '../findAll';\nimport { matchTextContent } from './matchTextContent';\n\nexport function matchLabelText(\n root: ReactTestInstance,\n element: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) {\n return (\n matchAccessibilityLabel(element, text, options) ||\n matchAccessibilityLabelledBy(\n root,\n element.props.accessibilityLabelledBy,\n text,\n options\n )\n );\n}\n\nfunction matchAccessibilityLabel(\n element: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions\n) {\n const { exact, normalizer } = options;\n return matches(text, element.props.accessibilityLabel, normalizer, exact);\n}\n\nfunction matchAccessibilityLabelledBy(\n root: ReactTestInstance,\n nativeId: string | undefined,\n text: TextMatch,\n options: TextMatchOptions\n) {\n if (!nativeId) {\n return false;\n }\n\n return (\n findAll(\n root,\n (node) =>\n node.props.nativeID === nativeId &&\n matchTextContent(node, text, options)\n ).length > 0\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEO,SAASG,cAAcA,CAC5BC,IAAuB,EACvBC,OAA0B,EAC1BC,IAAe,EACfC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,OACEC,uBAAuB,CAACH,OAAO,EAAEC,IAAI,EAAEC,OAAO,CAAC,IAC/CE,4BAA4B,CAC1BL,IAAI,EACJC,OAAO,CAACK,KAAK,CAACC,uBAAuB,EACrCL,IAAI,EACJC,OACF,CAAC;AAEL;AAEA,SAASC,uBAAuBA,CAC9BH,OAA0B,EAC1BC,IAAe,EACfC,OAAyB,EACzB;EACA,MAAM;IAAEK,KAAK;IAAEC;EAAW,CAAC,GAAGN,OAAO;EACrC,OAAO,IAAAO,gBAAO,EAACR,IAAI,EAAED,OAAO,CAACK,KAAK,CAACK,kBAAkB,EAAEF,UAAU,EAAED,KAAK,CAAC;AAC3E;AAEA,SAASH,4BAA4BA,CACnCL,IAAuB,EACvBY,QAA4B,EAC5BV,IAAe,EACfC,OAAyB,EACzB;EACA,IAAI,CAACS,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EAEA,OACE,IAAAC,gBAAO,EACLb,IAAI,EACHc,IAAI,IACHA,IAAI,CAACR,KAAK,CAACS,QAAQ,KAAKH,QAAQ,IAChC,IAAAI,kCAAgB,EAACF,IAAI,EAAEZ,IAAI,EAAEC,OAAO,CACxC,CAAC,CAACc,MAAM,GAAG,CAAC;AAEhB"}
1
+ {"version":3,"file":"matchLabelText.js","names":["_matches","require","_accessiblity","_findAll","_matchTextContent","matchLabelText","root","element","expectedText","options","matchAccessibilityLabel","matchAccessibilityLabelledBy","getAccessibilityLabelledBy","extpectedLabel","matches","getAccessibilityLabel","normalizer","exact","nativeId","text","findAll","node","props","nativeID","matchTextContent","length"],"sources":["../../../src/helpers/matchers/matchLabelText.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch, TextMatchOptions } from '../../matches';\nimport {\n getAccessibilityLabel,\n getAccessibilityLabelledBy,\n} from '../accessiblity';\nimport { findAll } from '../findAll';\nimport { matchTextContent } from './matchTextContent';\n\nexport function matchLabelText(\n root: ReactTestInstance,\n element: ReactTestInstance,\n expectedText: TextMatch,\n options: TextMatchOptions = {}\n) {\n return (\n matchAccessibilityLabel(element, expectedText, options) ||\n matchAccessibilityLabelledBy(\n root,\n getAccessibilityLabelledBy(element),\n expectedText,\n options\n )\n );\n}\n\nfunction matchAccessibilityLabel(\n element: ReactTestInstance,\n extpectedLabel: TextMatch,\n options: TextMatchOptions\n) {\n return matches(\n extpectedLabel,\n getAccessibilityLabel(element),\n options.normalizer,\n options.exact\n );\n}\n\nfunction matchAccessibilityLabelledBy(\n root: ReactTestInstance,\n nativeId: string | undefined,\n text: TextMatch,\n options: TextMatchOptions\n) {\n if (!nativeId) {\n return false;\n }\n\n return (\n findAll(\n root,\n (node) =>\n node.props.nativeID === nativeId &&\n matchTextContent(node, text, options)\n ).length > 0\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAEO,SAASI,cAAcA,CAC5BC,IAAuB,EACvBC,OAA0B,EAC1BC,YAAuB,EACvBC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,OACEC,uBAAuB,CAACH,OAAO,EAAEC,YAAY,EAAEC,OAAO,CAAC,IACvDE,4BAA4B,CAC1BL,IAAI,EACJ,IAAAM,wCAA0B,EAACL,OAAO,CAAC,EACnCC,YAAY,EACZC,OACF,CAAC;AAEL;AAEA,SAASC,uBAAuBA,CAC9BH,OAA0B,EAC1BM,cAAyB,EACzBJ,OAAyB,EACzB;EACA,OAAO,IAAAK,gBAAO,EACZD,cAAc,EACd,IAAAE,mCAAqB,EAACR,OAAO,CAAC,EAC9BE,OAAO,CAACO,UAAU,EAClBP,OAAO,CAACQ,KACV,CAAC;AACH;AAEA,SAASN,4BAA4BA,CACnCL,IAAuB,EACvBY,QAA4B,EAC5BC,IAAe,EACfV,OAAyB,EACzB;EACA,IAAI,CAACS,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EAEA,OACE,IAAAE,gBAAO,EACLd,IAAI,EACHe,IAAI,IACHA,IAAI,CAACC,KAAK,CAACC,QAAQ,KAAKL,QAAQ,IAChC,IAAAM,kCAAgB,EAACH,IAAI,EAAEF,IAAI,EAAEV,OAAO,CACxC,CAAC,CAACgB,MAAM,GAAG,CAAC;AAEhB"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.matchTextContent = matchTextContent;
7
7
  var _matches = require("../../matches");
8
- var _getTextContent = require("../getTextContent");
8
+ var _textContent = require("../text-content");
9
9
  /**
10
10
  * Matches the given node's text content against string or regex matcher.
11
11
  *
@@ -14,7 +14,7 @@ var _getTextContent = require("../getTextContent");
14
14
  * @returns - Whether the node's text content matches the given string or regex.
15
15
  */
16
16
  function matchTextContent(node, text, options = {}) {
17
- const textContent = (0, _getTextContent.getTextContent)(node);
17
+ const textContent = (0, _textContent.getTextContent)(node);
18
18
  const {
19
19
  exact,
20
20
  normalizer
@@ -1 +1 @@
1
- {"version":3,"file":"matchTextContent.js","names":["_matches","require","_getTextContent","matchTextContent","node","text","options","textContent","getTextContent","exact","normalizer","matches"],"sources":["../../../src/helpers/matchers/matchTextContent.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch, TextMatchOptions } from '../../matches';\nimport { getTextContent } from '../getTextContent';\n\n/**\n * Matches the given node's text content against string or regex matcher.\n *\n * @param node - Node which text content will be matched\n * @param text - The string or regex to match.\n * @returns - Whether the node's text content matches the given string or regex.\n */\nexport function matchTextContent(\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) {\n const textContent = getTextContent(node);\n const { exact, normalizer } = options;\n return matches(text, textContent, normalizer, exact);\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAC9BC,IAAuB,EACvBC,IAAe,EACfC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,MAAMC,WAAW,GAAG,IAAAC,8BAAc,EAACJ,IAAI,CAAC;EACxC,MAAM;IAAEK,KAAK;IAAEC;EAAW,CAAC,GAAGJ,OAAO;EACrC,OAAO,IAAAK,gBAAO,EAACN,IAAI,EAAEE,WAAW,EAAEG,UAAU,EAAED,KAAK,CAAC;AACtD"}
1
+ {"version":3,"file":"matchTextContent.js","names":["_matches","require","_textContent","matchTextContent","node","text","options","textContent","getTextContent","exact","normalizer","matches"],"sources":["../../../src/helpers/matchers/matchTextContent.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch, TextMatchOptions } from '../../matches';\nimport { getTextContent } from '../text-content';\n\n/**\n * Matches the given node's text content against string or regex matcher.\n *\n * @param node - Node which text content will be matched\n * @param text - The string or regex to match.\n * @returns - Whether the node's text content matches the given string or regex.\n */\nexport function matchTextContent(\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) {\n const textContent = getTextContent(node);\n const { exact, normalizer } = options;\n return matches(text, textContent, normalizer, exact);\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAC9BC,IAAuB,EACvBC,IAAe,EACfC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,MAAMC,WAAW,GAAG,IAAAC,2BAAc,EAACJ,IAAI,CAAC;EACxC,MAAM;IAAEK,KAAK;IAAEC;EAAW,CAAC,GAAGJ,OAAO;EACrC,OAAO,IAAAK,gBAAO,EAACN,IAAI,EAAEE,WAAW,EAAEG,UAAU,EAAED,KAAK,CAAC;AACtD"}
@@ -17,4 +17,4 @@ function getTextContent(element) {
17
17
  });
18
18
  return result.join('');
19
19
  }
20
- //# sourceMappingURL=getTextContent.js.map
20
+ //# sourceMappingURL=text-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-content.js","names":["getTextContent","element","result","children","forEach","child","push","join"],"sources":["../../src/helpers/text-content.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\n\nexport function getTextContent(\n element: ReactTestInstance | string | null\n): string {\n if (!element) {\n return '';\n }\n\n if (typeof element === 'string') {\n return element;\n }\n\n const result: string[] = [];\n element.children?.forEach((child) => {\n result.push(getTextContent(child));\n });\n\n return result.join('');\n}\n"],"mappings":";;;;;;AAEO,SAASA,cAAcA,CAC5BC,OAA0C,EAClC;EACR,IAAI,CAACA,OAAO,EAAE;IACZ,OAAO,EAAE;EACX;EAEA,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAOA,OAAO;EAChB;EAEA,MAAMC,MAAgB,GAAG,EAAE;EAC3BD,OAAO,CAACE,QAAQ,EAAEC,OAAO,CAAEC,KAAK,IAAK;IACnCH,MAAM,CAACI,IAAI,CAACN,cAAc,CAACK,KAAK,CAAC,CAAC;EACpC,CAAC,CAAC;EAEF,OAAOH,MAAM,CAACK,IAAI,CAAC,EAAE,CAAC;AACxB"}
@@ -0,0 +1,3 @@
1
+ import { ReactTestInstance } from 'react-test-renderer';
2
+ export declare function isTextInputEditable(element: ReactTestInstance): boolean;
3
+ export declare function getTextInputValue(element: ReactTestInstance): any;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTextInputValue = getTextInputValue;
7
+ exports.isTextInputEditable = isTextInputEditable;
8
+ var _hostComponentNames = require("./host-component-names");
9
+ function isTextInputEditable(element) {
10
+ if (!(0, _hostComponentNames.isHostTextInput)(element)) {
11
+ throw new Error(`Element is not a "TextInput", but it has type "${element.type}".`);
12
+ }
13
+ return element.props.editable !== false;
14
+ }
15
+ function getTextInputValue(element) {
16
+ if (!(0, _hostComponentNames.isHostTextInput)(element)) {
17
+ throw new Error(`Element is not a "TextInput", but it has type "${element.type}".`);
18
+ }
19
+ return element.props.value ?? element.props.defaultValue;
20
+ }
21
+ //# sourceMappingURL=text-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-input.js","names":["_hostComponentNames","require","isTextInputEditable","element","isHostTextInput","Error","type","props","editable","getTextInputValue","value","defaultValue"],"sources":["../../src/helpers/text-input.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { isHostTextInput } from './host-component-names';\n\nexport function isTextInputEditable(element: ReactTestInstance) {\n if (!isHostTextInput(element)) {\n throw new Error(\n `Element is not a \"TextInput\", but it has type \"${element.type}\".`\n );\n }\n\n return element.props.editable !== false;\n}\n\nexport function getTextInputValue(element: ReactTestInstance) {\n if (!isHostTextInput(element)) {\n throw new Error(\n `Element is not a \"TextInput\", but it has type \"${element.type}\".`\n );\n }\n\n return element.props.value ?? element.props.defaultValue;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,mBAAA,GAAAC,OAAA;AAEO,SAASC,mBAAmBA,CAACC,OAA0B,EAAE;EAC9D,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,KAAK,CACZ,kDAAiDF,OAAO,CAACG,IAAK,IACjE,CAAC;EACH;EAEA,OAAOH,OAAO,CAACI,KAAK,CAACC,QAAQ,KAAK,KAAK;AACzC;AAEO,SAASC,iBAAiBA,CAACN,OAA0B,EAAE;EAC5D,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,KAAK,CACZ,kDAAiDF,OAAO,CAACG,IAAK,IACjE,CAAC;EACH;EAEA,OAAOH,OAAO,CAACI,KAAK,CAACG,KAAK,IAAIP,OAAO,CAACI,KAAK,CAACI,YAAY;AAC1D"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=extend-expect.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend-expect.d.js","names":[],"sources":["../../src/matchers/extend-expect.d.ts"],"sourcesContent":["import type { TextMatch, TextMatchOptions } from '../matches';\n\nexport interface JestNativeMatchers<R> {\n toBeOnTheScreen(): R;\n toBeChecked(): R;\n toBeDisabled(): R;\n toBeEmptyElement(): R;\n toBeEnabled(): R;\n toBePartiallyChecked(): R;\n toBeVisible(): R;\n toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;\n toHaveProp(name: string, expectedValue?: unknown): R;\n toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;\n}\n\n// Implicit Jest global `expect`.\ndeclare global {\n namespace jest {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}\n }\n}\n\n// Explicit `@jest/globals` `expect` matchers.\ndeclare module '@jest/expect' {\n interface Matchers<R extends void | Promise<void>>\n extends JestNativeMatchers<R> {}\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ /// <reference path="../../src/matchers/extend-expect.d.ts" />
2
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _toBeOnTheScreen = require("./to-be-on-the-screen");
4
+ var _toBeChecked = require("./to-be-checked");
5
+ var _toBeDisabled = require("./to-be-disabled");
6
+ var _toBeEmptyElement = require("./to-be-empty-element");
7
+ var _toBePartiallyChecked = require("./to-be-partially-checked");
8
+ var _toBeVisible = require("./to-be-visible");
9
+ var _toHaveDisplayValue = require("./to-have-display-value");
10
+ var _toHaveProp = require("./to-have-prop");
11
+ var _toHaveTextContent = require("./to-have-text-content");
12
+ /// <reference path="./extend-expect.d.ts" />
13
+
14
+ expect.extend({
15
+ toBeOnTheScreen: _toBeOnTheScreen.toBeOnTheScreen,
16
+ toBeChecked: _toBeChecked.toBeChecked,
17
+ toBeDisabled: _toBeDisabled.toBeDisabled,
18
+ toBeEmptyElement: _toBeEmptyElement.toBeEmptyElement,
19
+ toBeEnabled: _toBeDisabled.toBeEnabled,
20
+ toBePartiallyChecked: _toBePartiallyChecked.toBePartiallyChecked,
21
+ toBeVisible: _toBeVisible.toBeVisible,
22
+ toHaveDisplayValue: _toHaveDisplayValue.toHaveDisplayValue,
23
+ toHaveProp: _toHaveProp.toHaveProp,
24
+ toHaveTextContent: _toHaveTextContent.toHaveTextContent
25
+ });
26
+ //# sourceMappingURL=extend-expect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend-expect.js","names":["_toBeOnTheScreen","require","_toBeChecked","_toBeDisabled","_toBeEmptyElement","_toBePartiallyChecked","_toBeVisible","_toHaveDisplayValue","_toHaveProp","_toHaveTextContent","expect","extend","toBeOnTheScreen","toBeChecked","toBeDisabled","toBeEmptyElement","toBeEnabled","toBePartiallyChecked","toBeVisible","toHaveDisplayValue","toHaveProp","toHaveTextContent"],"sources":["../../src/matchers/extend-expect.ts"],"sourcesContent":["/// <reference path=\"./extend-expect.d.ts\" />\n\nimport { toBeOnTheScreen } from './to-be-on-the-screen';\nimport { toBeChecked } from './to-be-checked';\nimport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nimport { toBeEmptyElement } from './to-be-empty-element';\nimport { toBePartiallyChecked } from './to-be-partially-checked';\nimport { toBeVisible } from './to-be-visible';\nimport { toHaveDisplayValue } from './to-have-display-value';\nimport { toHaveProp } from './to-have-prop';\nimport { toHaveTextContent } from './to-have-text-content';\n\nexpect.extend({\n toBeOnTheScreen,\n toBeChecked,\n toBeDisabled,\n toBeEmptyElement,\n toBeEnabled,\n toBePartiallyChecked,\n toBeVisible,\n toHaveDisplayValue,\n toHaveProp,\n toHaveTextContent,\n});\n"],"mappings":";;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,qBAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA;AAVA;;AAYAS,MAAM,CAACC,MAAM,CAAC;EACZC,eAAe,EAAfA,gCAAe;EACfC,WAAW,EAAXA,wBAAW;EACXC,YAAY,EAAZA,0BAAY;EACZC,gBAAgB,EAAhBA,kCAAgB;EAChBC,WAAW,EAAXA,yBAAW;EACXC,oBAAoB,EAApBA,0CAAoB;EACpBC,WAAW,EAAXA,wBAAW;EACXC,kBAAkB,EAAlBA,sCAAkB;EAClBC,UAAU,EAAVA,sBAAU;EACVC,iBAAiB,EAAjBA;AACF,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { toBeOnTheScreen } from './to-be-on-the-screen';
2
+ export { toBeChecked } from './to-be-checked';
3
+ export { toBeDisabled, toBeEnabled } from './to-be-disabled';
4
+ export { toBeEmptyElement } from './to-be-empty-element';
5
+ export { toBePartiallyChecked } from './to-be-partially-checked';
6
+ export { toBeVisible } from './to-be-visible';
7
+ export { toHaveDisplayValue } from './to-have-display-value';
8
+ export { toHaveProp } from './to-have-prop';
9
+ export { toHaveTextContent } from './to-have-text-content';
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "toBeChecked", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _toBeChecked.toBeChecked;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "toBeDisabled", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _toBeDisabled.toBeDisabled;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "toBeEmptyElement", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _toBeEmptyElement.toBeEmptyElement;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "toBeEnabled", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _toBeDisabled.toBeEnabled;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "toBeOnTheScreen", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _toBeOnTheScreen.toBeOnTheScreen;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "toBePartiallyChecked", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _toBePartiallyChecked.toBePartiallyChecked;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "toBeVisible", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _toBeVisible.toBeVisible;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "toHaveDisplayValue", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _toHaveDisplayValue.toHaveDisplayValue;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "toHaveProp", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _toHaveProp.toHaveProp;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "toHaveTextContent", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _toHaveTextContent.toHaveTextContent;
64
+ }
65
+ });
66
+ var _toBeOnTheScreen = require("./to-be-on-the-screen");
67
+ var _toBeChecked = require("./to-be-checked");
68
+ var _toBeDisabled = require("./to-be-disabled");
69
+ var _toBeEmptyElement = require("./to-be-empty-element");
70
+ var _toBePartiallyChecked = require("./to-be-partially-checked");
71
+ var _toBeVisible = require("./to-be-visible");
72
+ var _toHaveDisplayValue = require("./to-have-display-value");
73
+ var _toHaveProp = require("./to-have-prop");
74
+ var _toHaveTextContent = require("./to-have-text-content");
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_toBeOnTheScreen","require","_toBeChecked","_toBeDisabled","_toBeEmptyElement","_toBePartiallyChecked","_toBeVisible","_toHaveDisplayValue","_toHaveProp","_toHaveTextContent"],"sources":["../../src/matchers/index.tsx"],"sourcesContent":["export { toBeOnTheScreen } from './to-be-on-the-screen';\nexport { toBeChecked } from './to-be-checked';\nexport { toBeDisabled, toBeEnabled } from './to-be-disabled';\nexport { toBeEmptyElement } from './to-be-empty-element';\nexport { toBePartiallyChecked } from './to-be-partially-checked';\nexport { toBeVisible } from './to-be-visible';\nexport { toHaveDisplayValue } from './to-have-display-value';\nexport { toHaveProp } from './to-have-prop';\nexport { toHaveTextContent } from './to-have-text-content';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,qBAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBeChecked(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: boolean;
5
+ message: () => string;
6
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBeChecked = toBeChecked;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _accessiblity = require("../helpers/accessiblity");
9
+ var _errors = require("../helpers/errors");
10
+ var _utils = require("./utils");
11
+ function toBeChecked(element) {
12
+ (0, _utils.checkHostElement)(element, toBeChecked, this);
13
+ if (!hasValidAccessibilityRole(element)) {
14
+ throw new _errors.ErrorWithStack(`toBeChecked() works only on accessibility elements with "checkbox" or "radio" role.`, toBeChecked);
15
+ }
16
+ return {
17
+ pass: (0, _accessiblity.getAccessibilityCheckedState)(element) === true,
18
+ message: () => {
19
+ const is = this.isNot ? 'is' : 'is not';
20
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeChecked`, 'element', ''), '', `Received element ${is} checked:`, (0, _utils.formatElement)(element)].join('\n');
21
+ }
22
+ };
23
+ }
24
+ function hasValidAccessibilityRole(element) {
25
+ if (!(0, _accessiblity.isAccessibilityElement)(element)) {
26
+ return false;
27
+ }
28
+ const role = (0, _accessiblity.getAccessibilityRole)(element);
29
+ return role === 'checkbox' || role === 'radio';
30
+ }
31
+ //# sourceMappingURL=to-be-checked.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-checked.js","names":["_jestMatcherUtils","require","_accessiblity","_errors","_utils","toBeChecked","element","checkHostElement","hasValidAccessibilityRole","ErrorWithStack","pass","getAccessibilityCheckedState","message","is","isNot","matcherHint","formatElement","join","isAccessibilityElement","role","getAccessibilityRole"],"sources":["../../src/matchers/to-be-checked.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport {\n getAccessibilityCheckedState,\n getAccessibilityRole,\n isAccessibilityElement,\n} from '../helpers/accessiblity';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { checkHostElement, formatElement } from './utils';\n\nexport function toBeChecked(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n checkHostElement(element, toBeChecked, this);\n\n if (!hasValidAccessibilityRole(element)) {\n throw new ErrorWithStack(\n `toBeChecked() works only on accessibility elements with \"checkbox\" or \"radio\" role.`,\n toBeChecked\n );\n }\n\n return {\n pass: getAccessibilityCheckedState(element) === true,\n message: () => {\n const is = this.isNot ? 'is' : 'is not';\n return [\n matcherHint(`${this.isNot ? '.not' : ''}.toBeChecked`, 'element', ''),\n '',\n `Received element ${is} checked:`,\n formatElement(element),\n ].join('\\n');\n },\n };\n}\n\nfunction hasValidAccessibilityRole(element: ReactTestInstance) {\n if (!isAccessibilityElement(element)) {\n return false;\n }\n\n const role = getAccessibilityRole(element);\n return role === 'checkbox' || role === 'radio';\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,SAASI,WAAWA,CAEzBC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACD,OAAO,EAAED,WAAW,EAAE,IAAI,CAAC;EAE5C,IAAI,CAACG,yBAAyB,CAACF,OAAO,CAAC,EAAE;IACvC,MAAM,IAAIG,sBAAc,CACrB,qFAAoF,EACrFJ,WACF,CAAC;EACH;EAEA,OAAO;IACLK,IAAI,EAAE,IAAAC,0CAA4B,EAACL,OAAO,CAAC,KAAK,IAAI;IACpDM,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACC,KAAK,GAAG,IAAI,GAAG,QAAQ;MACvC,OAAO,CACL,IAAAC,6BAAW,EAAE,GAAE,IAAI,CAACD,KAAK,GAAG,MAAM,GAAG,EAAG,cAAa,EAAE,SAAS,EAAE,EAAE,CAAC,EACrE,EAAE,EACD,oBAAmBD,EAAG,WAAU,EACjC,IAAAG,oBAAa,EAACV,OAAO,CAAC,CACvB,CAACW,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH;AAEA,SAAST,yBAAyBA,CAACF,OAA0B,EAAE;EAC7D,IAAI,CAAC,IAAAY,oCAAsB,EAACZ,OAAO,CAAC,EAAE;IACpC,OAAO,KAAK;EACd;EAEA,MAAMa,IAAI,GAAG,IAAAC,kCAAoB,EAACd,OAAO,CAAC;EAC1C,OAAOa,IAAI,KAAK,UAAU,IAAIA,IAAI,KAAK,OAAO;AAChD"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBeDisabled(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: any;
5
+ message: () => string;
6
+ };
7
+ export declare function toBeEnabled(this: jest.MatcherContext, element: ReactTestInstance): {
8
+ pass: boolean;
9
+ message: () => string;
10
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBeDisabled = toBeDisabled;
7
+ exports.toBeEnabled = toBeEnabled;
8
+ var _jestMatcherUtils = require("jest-matcher-utils");
9
+ var _hostComponentNames = require("../helpers/host-component-names");
10
+ var _textInput = require("../helpers/text-input");
11
+ var _componentTree = require("../helpers/component-tree");
12
+ var _utils = require("./utils");
13
+ function toBeDisabled(element) {
14
+ (0, _utils.checkHostElement)(element, toBeDisabled, this);
15
+ const isDisabled = isElementDisabled(element) || isAncestorDisabled(element);
16
+ return {
17
+ pass: isDisabled,
18
+ message: () => {
19
+ const is = this.isNot ? 'is' : 'is not';
20
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeDisabled`, 'element', ''), '', `Received element ${is} disabled:`, (0, _utils.formatElement)(element)].join('\n');
21
+ }
22
+ };
23
+ }
24
+ function toBeEnabled(element) {
25
+ (0, _utils.checkHostElement)(element, toBeEnabled, this);
26
+ const isEnabled = !isElementDisabled(element) && !isAncestorDisabled(element);
27
+ return {
28
+ pass: isEnabled,
29
+ message: () => {
30
+ const is = this.isNot ? 'is' : 'is not';
31
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEnabled`, 'element', ''), '', `Received element ${is} enabled:`, (0, _utils.formatElement)(element)].join('\n');
32
+ }
33
+ };
34
+ }
35
+ function isElementDisabled(element) {
36
+ if ((0, _hostComponentNames.isHostTextInput)(element) && !(0, _textInput.isTextInputEditable)(element)) {
37
+ return true;
38
+ }
39
+ const {
40
+ accessibilityState,
41
+ 'aria-disabled': ariaDisabled
42
+ } = element.props;
43
+ return ariaDisabled ?? accessibilityState?.disabled ?? false;
44
+ }
45
+ function isAncestorDisabled(element) {
46
+ const parent = (0, _componentTree.getHostParent)(element);
47
+ if (parent == null) {
48
+ return false;
49
+ }
50
+ return isElementDisabled(parent) || isAncestorDisabled(parent);
51
+ }
52
+ //# sourceMappingURL=to-be-disabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-disabled.js","names":["_jestMatcherUtils","require","_hostComponentNames","_textInput","_componentTree","_utils","toBeDisabled","element","checkHostElement","isDisabled","isElementDisabled","isAncestorDisabled","pass","message","is","isNot","matcherHint","formatElement","join","toBeEnabled","isEnabled","isHostTextInput","isTextInputEditable","accessibilityState","ariaDisabled","props","disabled","parent","getHostParent"],"sources":["../../src/matchers/to-be-disabled.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isTextInputEditable } from '../helpers/text-input';\nimport { getHostParent } from '../helpers/component-tree';\nimport { checkHostElement, formatElement } from './utils';\n\nexport function toBeDisabled(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n checkHostElement(element, toBeDisabled, this);\n\n const isDisabled = isElementDisabled(element) || isAncestorDisabled(element);\n\n return {\n pass: isDisabled,\n message: () => {\n const is = this.isNot ? 'is' : 'is not';\n return [\n matcherHint(`${this.isNot ? '.not' : ''}.toBeDisabled`, 'element', ''),\n '',\n `Received element ${is} disabled:`,\n formatElement(element),\n ].join('\\n');\n },\n };\n}\n\nexport function toBeEnabled(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n checkHostElement(element, toBeEnabled, this);\n\n const isEnabled = !isElementDisabled(element) && !isAncestorDisabled(element);\n\n return {\n pass: isEnabled,\n message: () => {\n const is = this.isNot ? 'is' : 'is not';\n return [\n matcherHint(`${this.isNot ? '.not' : ''}.toBeEnabled`, 'element', ''),\n '',\n `Received element ${is} enabled:`,\n formatElement(element),\n ].join('\\n');\n },\n };\n}\n\nfunction isElementDisabled(element: ReactTestInstance) {\n if (isHostTextInput(element) && !isTextInputEditable(element)) {\n return true;\n }\n\n const { accessibilityState, 'aria-disabled': ariaDisabled } = element.props;\n return ariaDisabled ?? accessibilityState?.disabled ?? false;\n}\n\nfunction isAncestorDisabled(element: ReactTestInstance): boolean {\n const parent = getHostParent(element);\n if (parent == null) {\n return false;\n }\n\n return isElementDisabled(parent) || isAncestorDisabled(parent);\n}\n"],"mappings":";;;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEO,SAASK,YAAYA,CAE1BC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACD,OAAO,EAAED,YAAY,EAAE,IAAI,CAAC;EAE7C,MAAMG,UAAU,GAAGC,iBAAiB,CAACH,OAAO,CAAC,IAAII,kBAAkB,CAACJ,OAAO,CAAC;EAE5E,OAAO;IACLK,IAAI,EAAEH,UAAU;IAChBI,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACC,KAAK,GAAG,IAAI,GAAG,QAAQ;MACvC,OAAO,CACL,IAAAC,6BAAW,EAAE,GAAE,IAAI,CAACD,KAAK,GAAG,MAAM,GAAG,EAAG,eAAc,EAAE,SAAS,EAAE,EAAE,CAAC,EACtE,EAAE,EACD,oBAAmBD,EAAG,YAAW,EAClC,IAAAG,oBAAa,EAACV,OAAO,CAAC,CACvB,CAACW,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH;AAEO,SAASC,WAAWA,CAEzBZ,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACD,OAAO,EAAEY,WAAW,EAAE,IAAI,CAAC;EAE5C,MAAMC,SAAS,GAAG,CAACV,iBAAiB,CAACH,OAAO,CAAC,IAAI,CAACI,kBAAkB,CAACJ,OAAO,CAAC;EAE7E,OAAO;IACLK,IAAI,EAAEQ,SAAS;IACfP,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACC,KAAK,GAAG,IAAI,GAAG,QAAQ;MACvC,OAAO,CACL,IAAAC,6BAAW,EAAE,GAAE,IAAI,CAACD,KAAK,GAAG,MAAM,GAAG,EAAG,cAAa,EAAE,SAAS,EAAE,EAAE,CAAC,EACrE,EAAE,EACD,oBAAmBD,EAAG,WAAU,EACjC,IAAAG,oBAAa,EAACV,OAAO,CAAC,CACvB,CAACW,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH;AAEA,SAASR,iBAAiBA,CAACH,OAA0B,EAAE;EACrD,IAAI,IAAAc,mCAAe,EAACd,OAAO,CAAC,IAAI,CAAC,IAAAe,8BAAmB,EAACf,OAAO,CAAC,EAAE;IAC7D,OAAO,IAAI;EACb;EAEA,MAAM;IAAEgB,kBAAkB;IAAE,eAAe,EAAEC;EAAa,CAAC,GAAGjB,OAAO,CAACkB,KAAK;EAC3E,OAAOD,YAAY,IAAID,kBAAkB,EAAEG,QAAQ,IAAI,KAAK;AAC9D;AAEA,SAASf,kBAAkBA,CAACJ,OAA0B,EAAW;EAC/D,MAAMoB,MAAM,GAAG,IAAAC,4BAAa,EAACrB,OAAO,CAAC;EACrC,IAAIoB,MAAM,IAAI,IAAI,EAAE;IAClB,OAAO,KAAK;EACd;EAEA,OAAOjB,iBAAiB,CAACiB,MAAM,CAAC,IAAIhB,kBAAkB,CAACgB,MAAM,CAAC;AAChE"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="jest" />
2
+ import { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBeEmptyElement(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: boolean;
5
+ message: () => string;
6
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBeEmptyElement = toBeEmptyElement;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _componentTree = require("../helpers/component-tree");
9
+ var _utils = require("./utils");
10
+ function toBeEmptyElement(element) {
11
+ (0, _utils.checkHostElement)(element, toBeEmptyElement, this);
12
+ const hostChildren = (0, _componentTree.getHostChildren)(element);
13
+ return {
14
+ pass: hostChildren.length === 0,
15
+ message: () => {
16
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEmptyElement`, 'element', ''), '', 'Received:', `${(0, _jestMatcherUtils.RECEIVED_COLOR)((0, _utils.formatElementArray)(hostChildren))}`].join('\n');
17
+ }
18
+ };
19
+ }
20
+ //# sourceMappingURL=to-be-empty-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-empty-element.js","names":["_jestMatcherUtils","require","_componentTree","_utils","toBeEmptyElement","element","checkHostElement","hostChildren","getHostChildren","pass","length","message","matcherHint","isNot","RECEIVED_COLOR","formatElementArray","join"],"sources":["../../src/matchers/to-be-empty-element.tsx"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils';\nimport { getHostChildren } from '../helpers/component-tree';\nimport { checkHostElement, formatElementArray } from './utils';\n\nexport function toBeEmptyElement(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n checkHostElement(element, toBeEmptyElement, this);\n\n const hostChildren = getHostChildren(element);\n\n return {\n pass: hostChildren.length === 0,\n message: () => {\n return [\n matcherHint(\n `${this.isNot ? '.not' : ''}.toBeEmptyElement`,\n 'element',\n ''\n ),\n '',\n 'Received:',\n `${RECEIVED_COLOR(formatElementArray(hostChildren))}`,\n ].join('\\n');\n },\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEO,SAASG,gBAAgBA,CAE9BC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACD,OAAO,EAAED,gBAAgB,EAAE,IAAI,CAAC;EAEjD,MAAMG,YAAY,GAAG,IAAAC,8BAAe,EAACH,OAAO,CAAC;EAE7C,OAAO;IACLI,IAAI,EAAEF,YAAY,CAACG,MAAM,KAAK,CAAC;IAC/BC,OAAO,EAAEA,CAAA,KAAM;MACb,OAAO,CACL,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACC,KAAK,GAAG,MAAM,GAAG,EAAG,mBAAkB,EAC9C,SAAS,EACT,EACF,CAAC,EACD,EAAE,EACF,WAAW,EACV,GAAE,IAAAC,gCAAc,EAAC,IAAAC,yBAAkB,EAACR,YAAY,CAAC,CAAE,EAAC,CACtD,CAACS,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBeOnTheScreen(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: boolean;
5
+ message: () => string;
6
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBeOnTheScreen = toBeOnTheScreen;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _componentTree = require("../helpers/component-tree");
9
+ var _screen = require("../screen");
10
+ var _utils = require("./utils");
11
+ function toBeOnTheScreen(element) {
12
+ if (element !== null || !this.isNot) {
13
+ (0, _utils.checkHostElement)(element, toBeOnTheScreen, this);
14
+ }
15
+ const pass = element === null ? false : _screen.screen.UNSAFE_root === (0, _componentTree.getUnsafeRootElement)(element);
16
+ const errorFound = () => {
17
+ return `expected element tree not to contain element, but found\n${(0, _utils.formatElement)(element)}`;
18
+ };
19
+ const errorNotFound = () => {
20
+ return `element could not be found in the element tree`;
21
+ };
22
+ return {
23
+ pass,
24
+ message: () => {
25
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeOnTheScreen`, 'element', ''), '', (0, _jestMatcherUtils.RECEIVED_COLOR)(this.isNot ? errorFound() : errorNotFound())].join('\n');
26
+ }
27
+ };
28
+ }
29
+ //# sourceMappingURL=to-be-on-the-screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-on-the-screen.js","names":["_jestMatcherUtils","require","_componentTree","_screen","_utils","toBeOnTheScreen","element","isNot","checkHostElement","pass","screen","UNSAFE_root","getUnsafeRootElement","errorFound","formatElement","errorNotFound","message","matcherHint","RECEIVED_COLOR","join"],"sources":["../../src/matchers/to-be-on-the-screen.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils';\nimport { getUnsafeRootElement } from '../helpers/component-tree';\nimport { screen } from '../screen';\nimport { checkHostElement, formatElement } from './utils';\n\nexport function toBeOnTheScreen(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n if (element !== null || !this.isNot) {\n checkHostElement(element, toBeOnTheScreen, this);\n }\n\n const pass =\n element === null\n ? false\n : screen.UNSAFE_root === getUnsafeRootElement(element);\n\n const errorFound = () => {\n return `expected element tree not to contain element, but found\\n${formatElement(\n element\n )}`;\n };\n\n const errorNotFound = () => {\n return `element could not be found in the element tree`;\n };\n\n return {\n pass,\n message: () => {\n return [\n matcherHint(\n `${this.isNot ? '.not' : ''}.toBeOnTheScreen`,\n 'element',\n ''\n ),\n '',\n RECEIVED_COLOR(this.isNot ? errorFound() : errorNotFound()),\n ].join('\\n');\n },\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,SAASI,eAAeA,CAE7BC,OAA0B,EAC1B;EACA,IAAIA,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;IACnC,IAAAC,uBAAgB,EAACF,OAAO,EAAED,eAAe,EAAE,IAAI,CAAC;EAClD;EAEA,MAAMI,IAAI,GACRH,OAAO,KAAK,IAAI,GACZ,KAAK,GACLI,cAAM,CAACC,WAAW,KAAK,IAAAC,mCAAoB,EAACN,OAAO,CAAC;EAE1D,MAAMO,UAAU,GAAGA,CAAA,KAAM;IACvB,OAAQ,4DAA2D,IAAAC,oBAAa,EAC9ER,OACF,CAAE,EAAC;EACL,CAAC;EAED,MAAMS,aAAa,GAAGA,CAAA,KAAM;IAC1B,OAAQ,gDAA+C;EACzD,CAAC;EAED,OAAO;IACLN,IAAI;IACJO,OAAO,EAAEA,CAAA,KAAM;MACb,OAAO,CACL,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACV,KAAK,GAAG,MAAM,GAAG,EAAG,kBAAiB,EAC7C,SAAS,EACT,EACF,CAAC,EACD,EAAE,EACF,IAAAW,gCAAc,EAAC,IAAI,CAACX,KAAK,GAAGM,UAAU,CAAC,CAAC,GAAGE,aAAa,CAAC,CAAC,CAAC,CAC5D,CAACI,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBePartiallyChecked(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: boolean;
5
+ message: () => string;
6
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBePartiallyChecked = toBePartiallyChecked;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _accessiblity = require("../helpers/accessiblity");
9
+ var _errors = require("../helpers/errors");
10
+ var _utils = require("./utils");
11
+ function toBePartiallyChecked(element) {
12
+ (0, _utils.checkHostElement)(element, toBePartiallyChecked, this);
13
+ if (!hasValidAccessibilityRole(element)) {
14
+ throw new _errors.ErrorWithStack('toBePartiallyChecked() works only on accessibility elements with "checkbox" role.', toBePartiallyChecked);
15
+ }
16
+ return {
17
+ pass: (0, _accessiblity.getAccessibilityCheckedState)(element) === 'mixed',
18
+ message: () => {
19
+ const is = this.isNot ? 'is' : 'is not';
20
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBePartiallyChecked`, 'element', ''), '', `Received element ${is} partially checked:`, (0, _utils.formatElement)(element)].join('\n');
21
+ }
22
+ };
23
+ }
24
+ function hasValidAccessibilityRole(element) {
25
+ const role = (0, _accessiblity.getAccessibilityRole)(element);
26
+ return (0, _accessiblity.isAccessibilityElement)(element) && role === 'checkbox';
27
+ }
28
+ //# sourceMappingURL=to-be-partially-checked.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-partially-checked.js","names":["_jestMatcherUtils","require","_accessiblity","_errors","_utils","toBePartiallyChecked","element","checkHostElement","hasValidAccessibilityRole","ErrorWithStack","pass","getAccessibilityCheckedState","message","is","isNot","matcherHint","formatElement","join","role","getAccessibilityRole","isAccessibilityElement"],"sources":["../../src/matchers/to-be-partially-checked.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport {\n getAccessibilityCheckedState,\n getAccessibilityRole,\n isAccessibilityElement,\n} from '../helpers/accessiblity';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { checkHostElement, formatElement } from './utils';\n\nexport function toBePartiallyChecked(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n checkHostElement(element, toBePartiallyChecked, this);\n\n if (!hasValidAccessibilityRole(element)) {\n throw new ErrorWithStack(\n 'toBePartiallyChecked() works only on accessibility elements with \"checkbox\" role.',\n toBePartiallyChecked\n );\n }\n\n return {\n pass: getAccessibilityCheckedState(element) === 'mixed',\n message: () => {\n const is = this.isNot ? 'is' : 'is not';\n return [\n matcherHint(\n `${this.isNot ? '.not' : ''}.toBePartiallyChecked`,\n 'element',\n ''\n ),\n '',\n `Received element ${is} partially checked:`,\n formatElement(element),\n ].join('\\n');\n },\n };\n}\n\nfunction hasValidAccessibilityRole(element: ReactTestInstance) {\n const role = getAccessibilityRole(element);\n return isAccessibilityElement(element) && role === 'checkbox';\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,SAASI,oBAAoBA,CAElCC,OAA0B,EAC1B;EACA,IAAAC,uBAAgB,EAACD,OAAO,EAAED,oBAAoB,EAAE,IAAI,CAAC;EAErD,IAAI,CAACG,yBAAyB,CAACF,OAAO,CAAC,EAAE;IACvC,MAAM,IAAIG,sBAAc,CACtB,mFAAmF,EACnFJ,oBACF,CAAC;EACH;EAEA,OAAO;IACLK,IAAI,EAAE,IAAAC,0CAA4B,EAACL,OAAO,CAAC,KAAK,OAAO;IACvDM,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACC,KAAK,GAAG,IAAI,GAAG,QAAQ;MACvC,OAAO,CACL,IAAAC,6BAAW,EACR,GAAE,IAAI,CAACD,KAAK,GAAG,MAAM,GAAG,EAAG,uBAAsB,EAClD,SAAS,EACT,EACF,CAAC,EACD,EAAE,EACD,oBAAmBD,EAAG,qBAAoB,EAC3C,IAAAG,oBAAa,EAACV,OAAO,CAAC,CACvB,CAACW,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH;AAEA,SAAST,yBAAyBA,CAACF,OAA0B,EAAE;EAC7D,MAAMY,IAAI,GAAG,IAAAC,kCAAoB,EAACb,OAAO,CAAC;EAC1C,OAAO,IAAAc,oCAAsB,EAACd,OAAO,CAAC,IAAIY,IAAI,KAAK,UAAU;AAC/D"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="jest" />
2
+ import type { ReactTestInstance } from 'react-test-renderer';
3
+ export declare function toBeVisible(this: jest.MatcherContext, element: ReactTestInstance): {
4
+ pass: boolean;
5
+ message: () => string;
6
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBeVisible = toBeVisible;
7
+ var _jestMatcherUtils = require("jest-matcher-utils");
8
+ var _reactNative = require("react-native");
9
+ var _accessiblity = require("../helpers/accessiblity");
10
+ var _componentTree = require("../helpers/component-tree");
11
+ var _hostComponentNames = require("../helpers/host-component-names");
12
+ var _utils = require("./utils");
13
+ function toBeVisible(element) {
14
+ if (element !== null || !this.isNot) {
15
+ (0, _utils.checkHostElement)(element, toBeVisible, this);
16
+ }
17
+ return {
18
+ pass: isElementVisible(element),
19
+ message: () => {
20
+ const is = this.isNot ? 'is' : 'is not';
21
+ return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeVisible`, 'element', ''), '', `Received element ${is} visible:`, (0, _utils.formatElement)(element)].join('\n');
22
+ }
23
+ };
24
+ }
25
+ function isElementVisible(element, accessibilityCache) {
26
+ // Use cache to speed up repeated searches by `isHiddenFromAccessibility`.
27
+ const cache = accessibilityCache ?? new WeakMap();
28
+ if ((0, _accessiblity.isHiddenFromAccessibility)(element, {
29
+ cache
30
+ })) {
31
+ return false;
32
+ }
33
+ if (isHiddenForStyles(element)) {
34
+ return false;
35
+ }
36
+
37
+ // Note: this seems to be a bug in React Native.
38
+ // PR with fix: https://github.com/facebook/react-native/pull/39157
39
+ if ((0, _hostComponentNames.isHostModal)(element) && element.props.visible === false) {
40
+ return false;
41
+ }
42
+ const hostParent = (0, _componentTree.getHostParent)(element);
43
+ if (hostParent === null) {
44
+ return true;
45
+ }
46
+ return isElementVisible(hostParent, cache);
47
+ }
48
+ function isHiddenForStyles(element) {
49
+ const style = element.props.style ?? {};
50
+ const {
51
+ display,
52
+ opacity
53
+ } = _reactNative.StyleSheet.flatten(style);
54
+ return display === 'none' || opacity === 0;
55
+ }
56
+ //# sourceMappingURL=to-be-visible.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-be-visible.js","names":["_jestMatcherUtils","require","_reactNative","_accessiblity","_componentTree","_hostComponentNames","_utils","toBeVisible","element","isNot","checkHostElement","pass","isElementVisible","message","is","matcherHint","formatElement","join","accessibilityCache","cache","WeakMap","isHiddenFromAccessibility","isHiddenForStyles","isHostModal","props","visible","hostParent","getHostParent","style","display","opacity","StyleSheet","flatten"],"sources":["../../src/matchers/to-be-visible.tsx"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matcherHint } from 'jest-matcher-utils';\nimport { StyleSheet } from 'react-native';\nimport { isHiddenFromAccessibility } from '../helpers/accessiblity';\nimport { getHostParent } from '../helpers/component-tree';\nimport { isHostModal } from '../helpers/host-component-names';\nimport { checkHostElement, formatElement } from './utils';\n\nexport function toBeVisible(\n this: jest.MatcherContext,\n element: ReactTestInstance\n) {\n if (element !== null || !this.isNot) {\n checkHostElement(element, toBeVisible, this);\n }\n\n return {\n pass: isElementVisible(element),\n message: () => {\n const is = this.isNot ? 'is' : 'is not';\n return [\n matcherHint(`${this.isNot ? '.not' : ''}.toBeVisible`, 'element', ''),\n '',\n `Received element ${is} visible:`,\n formatElement(element),\n ].join('\\n');\n },\n };\n}\n\nfunction isElementVisible(\n element: ReactTestInstance,\n accessibilityCache?: WeakMap<ReactTestInstance, boolean>\n): boolean {\n // Use cache to speed up repeated searches by `isHiddenFromAccessibility`.\n const cache = accessibilityCache ?? new WeakMap<ReactTestInstance, boolean>();\n if (isHiddenFromAccessibility(element, { cache })) {\n return false;\n }\n\n if (isHiddenForStyles(element)) {\n return false;\n }\n\n // Note: this seems to be a bug in React Native.\n // PR with fix: https://github.com/facebook/react-native/pull/39157\n if (isHostModal(element) && element.props.visible === false) {\n return false;\n }\n\n const hostParent = getHostParent(element);\n if (hostParent === null) {\n return true;\n }\n\n return isElementVisible(hostParent, cache);\n}\n\nfunction isHiddenForStyles(element: ReactTestInstance) {\n const style = element.props.style ?? {};\n const { display, opacity } = StyleSheet.flatten(style);\n return display === 'none' || opacity === 0;\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAEO,SAASM,WAAWA,CAEzBC,OAA0B,EAC1B;EACA,IAAIA,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;IACnC,IAAAC,uBAAgB,EAACF,OAAO,EAAED,WAAW,EAAE,IAAI,CAAC;EAC9C;EAEA,OAAO;IACLI,IAAI,EAAEC,gBAAgB,CAACJ,OAAO,CAAC;IAC/BK,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,EAAE,GAAG,IAAI,CAACL,KAAK,GAAG,IAAI,GAAG,QAAQ;MACvC,OAAO,CACL,IAAAM,6BAAW,EAAE,GAAE,IAAI,CAACN,KAAK,GAAG,MAAM,GAAG,EAAG,cAAa,EAAE,SAAS,EAAE,EAAE,CAAC,EACrE,EAAE,EACD,oBAAmBK,EAAG,WAAU,EACjC,IAAAE,oBAAa,EAACR,OAAO,CAAC,CACvB,CAACS,IAAI,CAAC,IAAI,CAAC;IACd;EACF,CAAC;AACH;AAEA,SAASL,gBAAgBA,CACvBJ,OAA0B,EAC1BU,kBAAwD,EAC/C;EACT;EACA,MAAMC,KAAK,GAAGD,kBAAkB,IAAI,IAAIE,OAAO,CAA6B,CAAC;EAC7E,IAAI,IAAAC,uCAAyB,EAACb,OAAO,EAAE;IAAEW;EAAM,CAAC,CAAC,EAAE;IACjD,OAAO,KAAK;EACd;EAEA,IAAIG,iBAAiB,CAACd,OAAO,CAAC,EAAE;IAC9B,OAAO,KAAK;EACd;;EAEA;EACA;EACA,IAAI,IAAAe,+BAAW,EAACf,OAAO,CAAC,IAAIA,OAAO,CAACgB,KAAK,CAACC,OAAO,KAAK,KAAK,EAAE;IAC3D,OAAO,KAAK;EACd;EAEA,MAAMC,UAAU,GAAG,IAAAC,4BAAa,EAACnB,OAAO,CAAC;EACzC,IAAIkB,UAAU,KAAK,IAAI,EAAE;IACvB,OAAO,IAAI;EACb;EAEA,OAAOd,gBAAgB,CAACc,UAAU,EAAEP,KAAK,CAAC;AAC5C;AAEA,SAASG,iBAAiBA,CAACd,OAA0B,EAAE;EACrD,MAAMoB,KAAK,GAAGpB,OAAO,CAACgB,KAAK,CAACI,KAAK,IAAI,CAAC,CAAC;EACvC,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGC,uBAAU,CAACC,OAAO,CAACJ,KAAK,CAAC;EACtD,OAAOC,OAAO,KAAK,MAAM,IAAIC,OAAO,KAAK,CAAC;AAC5C"}