@testing-library/react-native 11.3.0 → 11.5.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 (126) hide show
  1. package/README.md +5 -2
  2. package/build/act.js +9 -15
  3. package/build/act.js.map +1 -1
  4. package/build/cleanup.d.ts +1 -1
  5. package/build/cleanup.js +0 -4
  6. package/build/cleanup.js.map +1 -1
  7. package/build/config.d.ts +15 -2
  8. package/build/config.js +16 -8
  9. package/build/config.js.map +1 -1
  10. package/build/fireEvent.js +3 -31
  11. package/build/fireEvent.js.map +1 -1
  12. package/build/flushMicroTasks.d.ts +1 -1
  13. package/build/flushMicroTasks.js +0 -3
  14. package/build/flushMicroTasks.js.map +1 -1
  15. package/build/helpers/accessiblity.d.ts +10 -1
  16. package/build/helpers/accessiblity.js +28 -24
  17. package/build/helpers/accessiblity.js.map +1 -1
  18. package/build/helpers/component-tree.js +6 -27
  19. package/build/helpers/component-tree.js.map +1 -1
  20. package/build/helpers/debugDeep.d.ts +5 -1
  21. package/build/helpers/debugDeep.js +7 -6
  22. package/build/helpers/debugDeep.js.map +1 -1
  23. package/build/helpers/debugShallow.js +0 -5
  24. package/build/helpers/debugShallow.js.map +1 -1
  25. package/build/helpers/errors.js +4 -25
  26. package/build/helpers/errors.js.map +1 -1
  27. package/build/helpers/filterNodeByType.js +0 -2
  28. package/build/helpers/filterNodeByType.js.map +1 -1
  29. package/build/helpers/findAll.d.ts +10 -0
  30. package/build/helpers/findAll.js +44 -0
  31. package/build/helpers/findAll.js.map +1 -0
  32. package/build/helpers/format.d.ts +5 -1
  33. package/build/helpers/format.js +17 -7
  34. package/build/helpers/format.js.map +1 -1
  35. package/build/helpers/getTextContent.d.ts +2 -0
  36. package/build/helpers/getTextContent.js +20 -0
  37. package/build/helpers/getTextContent.js.map +1 -0
  38. package/build/helpers/matchers/accessibilityState.d.ts +3 -0
  39. package/build/helpers/matchers/accessibilityState.js +28 -0
  40. package/build/helpers/matchers/accessibilityState.js.map +1 -0
  41. package/build/helpers/matchers/accessibilityValue.d.ts +9 -0
  42. package/build/helpers/matchers/accessibilityValue.js +12 -0
  43. package/build/helpers/matchers/accessibilityValue.js.map +1 -0
  44. package/build/helpers/matchers/matchArrayProp.js +0 -3
  45. package/build/helpers/matchers/matchArrayProp.js.map +1 -1
  46. package/build/helpers/matchers/matchObjectProp.js +0 -2
  47. package/build/helpers/matchers/matchObjectProp.js.map +1 -1
  48. package/build/helpers/matchers/matchStringProp.js +0 -3
  49. package/build/helpers/matchers/matchStringProp.js.map +1 -1
  50. package/build/helpers/matchers/matchTextContent.d.ts +3 -0
  51. package/build/helpers/matchers/matchTextContent.js +22 -0
  52. package/build/helpers/matchers/matchTextContent.js.map +1 -0
  53. package/build/helpers/stringValidation.js +0 -7
  54. package/build/helpers/stringValidation.js.map +1 -1
  55. package/build/helpers/timers.js +10 -21
  56. package/build/helpers/timers.js.map +1 -1
  57. package/build/index.flow.js +169 -56
  58. package/build/index.js +0 -6
  59. package/build/index.js.map +1 -1
  60. package/build/matches.d.ts +7 -3
  61. package/build/matches.js +2 -4
  62. package/build/matches.js.map +1 -1
  63. package/build/pure.d.ts +12 -23
  64. package/build/pure.js +8 -15
  65. package/build/pure.js.map +1 -1
  66. package/build/queries/a11yState.d.ts +15 -14
  67. package/build/queries/a11yState.js +16 -13
  68. package/build/queries/a11yState.js.map +1 -1
  69. package/build/queries/a11yValue.d.ts +15 -20
  70. package/build/queries/a11yValue.js +16 -13
  71. package/build/queries/a11yValue.js.map +1 -1
  72. package/build/queries/displayValue.d.ts +11 -9
  73. package/build/queries/displayValue.js +2 -12
  74. package/build/queries/displayValue.js.map +1 -1
  75. package/build/queries/hintText.d.ts +23 -20
  76. package/build/queries/hintText.js +11 -11
  77. package/build/queries/hintText.js.map +1 -1
  78. package/build/queries/labelText.d.ts +11 -8
  79. package/build/queries/labelText.js +11 -11
  80. package/build/queries/labelText.js.map +1 -1
  81. package/build/queries/makeQueries.d.ts +9 -9
  82. package/build/queries/makeQueries.js +40 -24
  83. package/build/queries/makeQueries.js.map +1 -1
  84. package/build/queries/options.d.ts +11 -0
  85. package/build/queries/options.js +2 -0
  86. package/build/queries/options.js.map +1 -0
  87. package/build/queries/placeholderText.d.ts +11 -9
  88. package/build/queries/placeholderText.js +2 -12
  89. package/build/queries/placeholderText.js.map +1 -1
  90. package/build/queries/role.d.ts +7 -3
  91. package/build/queries/role.js +32 -13
  92. package/build/queries/role.js.map +1 -1
  93. package/build/queries/testId.d.ts +11 -9
  94. package/build/queries/testId.js +3 -11
  95. package/build/queries/testId.js.map +1 -1
  96. package/build/queries/text.d.ts +11 -13
  97. package/build/queries/text.js +6 -71
  98. package/build/queries/text.js.map +1 -1
  99. package/build/queries/unsafeProps.d.ts +1 -1
  100. package/build/queries/unsafeProps.js +2 -11
  101. package/build/queries/unsafeProps.js.map +1 -1
  102. package/build/queries/unsafeType.d.ts +1 -1
  103. package/build/queries/unsafeType.js +2 -9
  104. package/build/queries/unsafeType.js.map +1 -1
  105. package/build/react-versions.js +0 -4
  106. package/build/react-versions.js.map +1 -1
  107. package/build/render.d.ts +88 -141
  108. package/build/render.js +21 -31
  109. package/build/render.js.map +1 -1
  110. package/build/renderHook.d.ts +2 -2
  111. package/build/renderHook.js +2 -12
  112. package/build/renderHook.js.map +1 -1
  113. package/build/screen.js +0 -6
  114. package/build/screen.js.map +1 -1
  115. package/build/shallow.js +0 -6
  116. package/build/shallow.js.map +1 -1
  117. package/build/waitFor.d.ts +1 -1
  118. package/build/waitFor.js +29 -52
  119. package/build/waitFor.js.map +1 -1
  120. package/build/waitForElementToBeRemoved.js +2 -11
  121. package/build/waitForElementToBeRemoved.js.map +1 -1
  122. package/build/within.d.ts +84 -138
  123. package/build/within.js +2 -14
  124. package/build/within.js.map +1 -1
  125. package/package.json +12 -11
  126. package/typings/index.flow.js +169 -56
@@ -1 +1 @@
1
- {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","shallow","defaultScreen","container","debug","update","unmount","rerender","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByA11yState","getAllByA11yState","queryByA11yState","queryAllByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState","getByA11yValue","getAllByA11yValue","queryByA11yValue","queryAllByA11yValue","findByA11yValue","findAllByA11yValue","getByAccessibilityValue","getAllByAccessibilityValue","queryByAccessibilityValue","queryAllByAccessibilityValue","findByAccessibilityValue","findAllByAccessibilityValue","UNSAFE_getByProps","UNSAFE_getAllByProps","UNSAFE_queryByProps","UNSAFE_queryAllByProps","UNSAFE_getByType","UNSAFE_getAllByType","UNSAFE_queryByType","UNSAFE_queryAllByType","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","setRenderResult","output","clearRenderResult"],"sources":["../src/screen.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\nconst notImplementedDebug = () => {\n throw new Error(SCREEN_ERROR);\n};\nnotImplementedDebug.shallow = notImplemented;\n\nconst defaultScreen: RenderResult = {\n get container(): ReactTestInstance {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplementedDebug,\n update: notImplemented,\n unmount: notImplemented,\n rerender: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByA11yState: notImplemented,\n getAllByA11yState: notImplemented,\n queryByA11yState: notImplemented,\n queryAllByA11yState: notImplemented,\n findByA11yState: notImplemented,\n findAllByA11yState: notImplemented,\n getByAccessibilityState: notImplemented,\n getAllByAccessibilityState: notImplemented,\n queryByAccessibilityState: notImplemented,\n queryAllByAccessibilityState: notImplemented,\n findByAccessibilityState: notImplemented,\n findAllByAccessibilityState: notImplemented,\n getByA11yValue: notImplemented,\n getAllByA11yValue: notImplemented,\n queryByA11yValue: notImplemented,\n queryAllByA11yValue: notImplemented,\n findByA11yValue: notImplemented,\n findAllByA11yValue: notImplemented,\n getByAccessibilityValue: notImplemented,\n getAllByAccessibilityValue: notImplemented,\n queryByAccessibilityValue: notImplemented,\n queryAllByAccessibilityValue: notImplemented,\n findByAccessibilityValue: notImplemented,\n findAllByAccessibilityValue: notImplemented,\n UNSAFE_getByProps: notImplemented,\n UNSAFE_getAllByProps: notImplemented,\n UNSAFE_queryByProps: notImplemented,\n UNSAFE_queryAllByProps: notImplemented,\n UNSAFE_getByType: notImplemented,\n UNSAFE_getAllByType: notImplemented,\n UNSAFE_queryByType: notImplemented,\n UNSAFE_queryAllByType: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: RenderResult = defaultScreen;\n\nexport function setRenderResult(output: RenderResult) {\n screen = output;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"mappings":";;;;;;;;AAGA,MAAMA,YAAY,GAAG,qCAArB;;AAEA,MAAMC,cAAc,GAAG,MAAM;EAC3B,MAAM,IAAIC,KAAJ,CAAUF,YAAV,CAAN;AACD,CAFD;;AAIA,MAAMG,mBAAmB,GAAG,MAAM;EAChC,MAAM,IAAID,KAAJ,CAAUF,YAAV,CAAN;AACD,CAFD;;AAGAG,mBAAmB,CAACC,OAApB,GAA8BH,cAA9B;AAEA,MAAMI,aAA2B,GAAG;EAClC,IAAIC,SAAJ,GAAmC;IACjC,MAAM,IAAIJ,KAAJ,CAAU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E,iBAAiB,EAAE/E,cA7Ee;EA8ElCgF,oBAAoB,EAAEhF,cA9EY;EA+ElCiF,mBAAmB,EAAEjF,cA/Ea;EAgFlCkF,sBAAsB,EAAElF,cAhFU;EAiFlCmF,kBAAkB,EAAEnF,cAjFc;EAkFlCoF,qBAAqB,EAAEpF,cAlFW;EAmFlCqF,WAAW,EAAErF,cAnFqB;EAoFlCsF,cAAc,EAAEtF,cApFkB;EAqFlCuF,aAAa,EAAEvF,cArFmB;EAsFlCwF,gBAAgB,EAAExF,cAtFgB;EAuFlCyF,YAAY,EAAEzF,cAvFoB;EAwFlC0F,eAAe,EAAE1F,cAxFiB;EAyFlC2F,SAAS,EAAE3F,cAzFuB;EA0FlC4F,YAAY,EAAE5F,cA1FoB;EA2FlC6F,WAAW,EAAE7F,cA3FqB;EA4FlC8F,cAAc,EAAE9F,cA5FkB;EA6FlC+F,UAAU,EAAE/F,cA7FsB;EA8FlCgG,aAAa,EAAEhG;AA9FmB,CAApC;AAiGO,IAAIiG,MAAoB,GAAG7F,aAA3B;;;AAEA,SAAS8F,eAAT,CAAyBC,MAAzB,EAA+C;EACpD,iBAAAF,MAAM,GAAGE,MAAT;AACD;;AAEM,SAASC,iBAAT,GAA6B;EAClC,iBAAAH,MAAM,GAAG7F,aAAT;AACD"}
1
+ {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","shallow","defaultScreen","container","debug","update","unmount","rerender","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByA11yState","getAllByA11yState","queryByA11yState","queryAllByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState","getByA11yValue","getAllByA11yValue","queryByA11yValue","queryAllByA11yValue","findByA11yValue","findAllByA11yValue","getByAccessibilityValue","getAllByAccessibilityValue","queryByAccessibilityValue","queryAllByAccessibilityValue","findByAccessibilityValue","findAllByAccessibilityValue","UNSAFE_getByProps","UNSAFE_getAllByProps","UNSAFE_queryByProps","UNSAFE_queryAllByProps","UNSAFE_getByType","UNSAFE_getAllByType","UNSAFE_queryByType","UNSAFE_queryAllByType","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","setRenderResult","output","clearRenderResult"],"sources":["../src/screen.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\nconst notImplementedDebug = () => {\n throw new Error(SCREEN_ERROR);\n};\nnotImplementedDebug.shallow = notImplemented;\n\nconst defaultScreen: RenderResult = {\n get container(): ReactTestInstance {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplementedDebug,\n update: notImplemented,\n unmount: notImplemented,\n rerender: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByA11yState: notImplemented,\n getAllByA11yState: notImplemented,\n queryByA11yState: notImplemented,\n queryAllByA11yState: notImplemented,\n findByA11yState: notImplemented,\n findAllByA11yState: notImplemented,\n getByAccessibilityState: notImplemented,\n getAllByAccessibilityState: notImplemented,\n queryByAccessibilityState: notImplemented,\n queryAllByAccessibilityState: notImplemented,\n findByAccessibilityState: notImplemented,\n findAllByAccessibilityState: notImplemented,\n getByA11yValue: notImplemented,\n getAllByA11yValue: notImplemented,\n queryByA11yValue: notImplemented,\n queryAllByA11yValue: notImplemented,\n findByA11yValue: notImplemented,\n findAllByA11yValue: notImplemented,\n getByAccessibilityValue: notImplemented,\n getAllByAccessibilityValue: notImplemented,\n queryByAccessibilityValue: notImplemented,\n queryAllByAccessibilityValue: notImplemented,\n findByAccessibilityValue: notImplemented,\n findAllByAccessibilityValue: notImplemented,\n UNSAFE_getByProps: notImplemented,\n UNSAFE_getAllByProps: notImplemented,\n UNSAFE_queryByProps: notImplemented,\n UNSAFE_queryAllByProps: notImplemented,\n UNSAFE_getByType: notImplemented,\n UNSAFE_getAllByType: notImplemented,\n UNSAFE_queryByType: notImplemented,\n UNSAFE_queryAllByType: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: RenderResult = defaultScreen;\n\nexport function setRenderResult(output: RenderResult) {\n screen = output;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"mappings":";;;;;;;;AAGA,MAAMA,YAAY,GAAG,qCAAqC;AAE1D,MAAMC,cAAc,GAAG,MAAM;EAC3B,MAAM,IAAIC,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AAED,MAAMG,mBAAmB,GAAG,MAAM;EAChC,MAAM,IAAID,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AACDG,mBAAmB,CAACC,OAAO,GAAGH,cAAc;AAE5C,MAAMI,aAA2B,GAAG;EAClC,IAAIC,SAAS,GAAsB;IACjC,MAAM,IAAIJ,KAAK,CAACF,YAAY,CAAC;EAC/B,CAAC;EACDO,KAAK,EAAEJ,mBAAmB;EAC1BK,MAAM,EAAEP,cAAc;EACtBQ,OAAO,EAAER,cAAc;EACvBS,QAAQ,EAAET,cAAc;EACxBU,MAAM,EAAEV,cAAc;EACtBW,cAAc,EAAEX,cAAc;EAC9BY,iBAAiB,EAAEZ,cAAc;EACjCa,gBAAgB,EAAEb,cAAc;EAChCc,mBAAmB,EAAEd,cAAc;EACnCe,eAAe,EAAEf,cAAc;EAC/BgB,kBAAkB,EAAEhB,cAAc;EAClCiB,aAAa,EAAEjB,cAAc;EA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AAa;AAAC;AAEzC,SAAS8F,eAAe,CAACC,MAAoB,EAAE;EACpD,iBAAAF,MAAM,GAAGE,MAAM;AACjB;AAEO,SAASC,iBAAiB,GAAG;EAClC,iBAAAH,MAAM,GAAG7F,aAAa;AACxB"}
package/build/shallow.js CHANGED
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.shallowInternal = shallowInternal;
7
-
8
7
  var React = _interopRequireWildcard(require("react"));
9
-
10
8
  var _shallow = _interopRequireDefault(require("react-test-renderer/shallow"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  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); }
15
-
16
11
  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; }
17
-
18
12
  // eslint-disable-line import/no-extraneous-dependencies
19
13
 
20
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"shallow.js","names":["shallowInternal","instance","renderer","ShallowRenderer","render","React","createElement","type","props","output","getRenderOutput"],"sources":["../src/shallow.ts"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies\n\n/**\n * Renders test component shallowly using react-test-renderer/shallow\n */\nexport function shallowInternal(\n instance: ReactTestInstance | React.ReactElement<any>\n): { output: any } {\n const renderer = new (ShallowRenderer as any)();\n\n renderer.render(React.createElement(instance.type, instance.props));\n\n return {\n output: renderer.getRenderOutput(),\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAA2D;;AAE3D;AACA;AACA;AACO,SAASA,eAAT,CACLC,QADK,EAEY;EACjB,MAAMC,QAAQ,GAAG,IAAKC,gBAAL,EAAjB;EAEAD,QAAQ,CAACE,MAAT,eAAgBC,KAAK,CAACC,aAAN,CAAoBL,QAAQ,CAACM,IAA7B,EAAmCN,QAAQ,CAACO,KAA5C,CAAhB;EAEA,OAAO;IACLC,MAAM,EAAEP,QAAQ,CAACQ,eAAT;EADH,CAAP;AAGD"}
1
+ {"version":3,"file":"shallow.js","names":["shallowInternal","instance","renderer","ShallowRenderer","render","React","createElement","type","props","output","getRenderOutput"],"sources":["../src/shallow.ts"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies\n\n/**\n * Renders test component shallowly using react-test-renderer/shallow\n */\nexport function shallowInternal(\n instance: ReactTestInstance | React.ReactElement<any>\n): { output: any } {\n const renderer = new (ShallowRenderer as any)();\n\n renderer.render(React.createElement(instance.type, instance.props));\n\n return {\n output: renderer.getRenderOutput(),\n };\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAA0D;AAAA;AAAA;AAAC;;AAE3D;AACA;AACA;AACO,SAASA,eAAe,CAC7BC,QAAqD,EACpC;EACjB,MAAMC,QAAQ,GAAG,IAAKC,gBAAe,EAAU;EAE/CD,QAAQ,CAACE,MAAM,eAACC,KAAK,CAACC,aAAa,CAACL,QAAQ,CAACM,IAAI,EAAEN,QAAQ,CAACO,KAAK,CAAC,CAAC;EAEnE,OAAO;IACLC,MAAM,EAAEP,QAAQ,CAACQ,eAAe;EAClC,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import { ErrorWithStack } from './helpers/errors';
2
- export declare type WaitForOptions = {
2
+ export type WaitForOptions = {
3
3
  timeout?: number;
4
4
  interval?: number;
5
5
  stackTraceError?: ErrorWithStack;
package/build/waitFor.js CHANGED
@@ -4,24 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = waitFor;
7
-
8
7
  var _act = _interopRequireWildcard(require("./act"));
9
-
10
8
  var _config = require("./config");
11
-
12
9
  var _errors = require("./helpers/errors");
13
-
14
10
  var _timers = require("./helpers/timers");
15
-
16
11
  var _reactVersions = require("./react-versions");
17
-
18
12
  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); }
19
-
20
13
  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; }
21
-
22
14
  /* globals jest */
23
- const DEFAULT_INTERVAL = 50;
24
15
 
16
+ const DEFAULT_INTERVAL = 50;
25
17
  function waitForInternal(expectation, {
26
18
  timeout = (0, _config.getConfig)().asyncUtilTimeout,
27
19
  interval = DEFAULT_INTERVAL,
@@ -30,107 +22,102 @@ function waitForInternal(expectation, {
30
22
  }) {
31
23
  if (typeof expectation !== 'function') {
32
24
  throw new TypeError('Received `expectation` arg must be a function');
33
- } // eslint-disable-next-line no-async-promise-executor
34
-
25
+ }
35
26
 
27
+ // eslint-disable-next-line no-async-promise-executor
36
28
  return new Promise(async (resolve, reject) => {
37
29
  let lastError, intervalId;
38
30
  let finished = false;
39
31
  let promiseStatus = 'idle';
40
- const overallTimeoutTimer = (0, _timers.setTimeout)(handleTimeout, timeout);
32
+ let overallTimeoutTimer = null;
41
33
  const usingFakeTimers = (0, _timers.jestFakeTimersAreEnabled)();
42
-
43
34
  if (usingFakeTimers) {
44
- checkExpectation(); // this is a dangerous rule to disable because it could lead to an
35
+ checkExpectation();
36
+ // this is a dangerous rule to disable because it could lead to an
45
37
  // infinite loop. However, eslint isn't smart enough to know that we're
46
38
  // setting finished inside `onDone` which will be called when we're done
47
39
  // waiting or when we've timed out.
48
40
  // eslint-disable-next-line no-unmodified-loop-condition
49
-
50
41
  let fakeTimeRemaining = timeout;
51
-
52
42
  while (!finished) {
53
43
  if (!(0, _timers.jestFakeTimersAreEnabled)()) {
54
44
  const error = new Error(`Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);
55
-
56
45
  if (stackTraceError) {
57
46
  (0, _errors.copyStackTrace)(error, stackTraceError);
58
47
  }
59
-
60
48
  reject(error);
61
49
  return;
62
- } // when fake timers are used we want to simulate the interval time passing
63
-
50
+ }
64
51
 
52
+ // when fake timers are used we want to simulate the interval time passing
65
53
  if (fakeTimeRemaining <= 0) {
54
+ handleTimeout();
66
55
  return;
67
56
  } else {
68
57
  fakeTimeRemaining -= interval;
69
- } // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's
58
+ }
59
+
60
+ // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's
70
61
  // possible that could make this loop go on forever if someone is using
71
62
  // third party code that's setting up recursive timers so rapidly that
72
63
  // the user's timer's don't get a chance to resolve. So we'll advance
73
64
  // by an interval instead. (We have a test for this case).
65
+ jest.advanceTimersByTime(interval);
74
66
 
75
-
76
- jest.advanceTimersByTime(interval); // It's really important that checkExpectation is run *before* we flush
67
+ // It's really important that checkExpectation is run *before* we flush
77
68
  // in-flight promises. To be honest, I'm not sure why, and I can't quite
78
69
  // think of a way to reproduce the problem in a test, but I spent
79
70
  // an entire day banging my head against a wall on this.
71
+ checkExpectation();
80
72
 
81
- checkExpectation(); // In this rare case, we *need* to wait for in-flight promises
73
+ // In this rare case, we *need* to wait for in-flight promises
82
74
  // to resolve before continuing. We don't need to take advantage
83
75
  // of parallelization so we're fine.
84
76
  // https://stackoverflow.com/a/59243586/971592
85
77
  // eslint-disable-next-line no-await-in-loop
86
-
87
78
  await new Promise(resolve => (0, _timers.setImmediate)(resolve));
88
79
  }
89
80
  } else {
81
+ overallTimeoutTimer = (0, _timers.setTimeout)(handleTimeout, timeout);
90
82
  intervalId = setInterval(checkRealTimersCallback, interval);
91
83
  checkExpectation();
92
84
  }
93
-
94
85
  function onDone(done) {
95
86
  finished = true;
96
- (0, _timers.clearTimeout)(overallTimeoutTimer);
97
-
87
+ if (overallTimeoutTimer) {
88
+ (0, _timers.clearTimeout)(overallTimeoutTimer);
89
+ }
98
90
  if (!usingFakeTimers) {
99
91
  clearInterval(intervalId);
100
92
  }
101
-
102
93
  if (done.type === 'error') {
103
94
  reject(done.error);
104
95
  } else {
105
96
  resolve(done.result);
106
97
  }
107
98
  }
108
-
109
99
  function checkRealTimersCallback() {
110
100
  if ((0, _timers.jestFakeTimersAreEnabled)()) {
111
101
  const error = new Error(`Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);
112
-
113
102
  if (stackTraceError) {
114
103
  (0, _errors.copyStackTrace)(error, stackTraceError);
115
104
  }
116
-
117
105
  return reject(error);
118
106
  } else {
119
107
  return checkExpectation();
120
108
  }
121
109
  }
122
-
123
110
  function checkExpectation() {
124
111
  if (promiseStatus === 'pending') return;
125
-
126
112
  try {
127
- const result = expectation(); // @ts-ignore result can be a promise
128
- // eslint-disable-next-line promise/prefer-await-to-then
113
+ const result = expectation();
129
114
 
115
+ // @ts-ignore result can be a promise
116
+ // eslint-disable-next-line promise/prefer-await-to-then
130
117
  if (typeof result?.then === 'function') {
131
118
  const promiseResult = result;
132
- promiseStatus = 'pending'; // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
133
-
119
+ promiseStatus = 'pending';
120
+ // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
134
121
  promiseResult.then(resolvedValue => {
135
122
  promiseStatus = 'resolved';
136
123
  onDone({
@@ -148,35 +135,29 @@ function waitForInternal(expectation, {
148
135
  type: 'result',
149
136
  result: result
150
137
  });
151
- } // If `callback` throws, wait for the next mutation, interval, or timeout.
152
-
138
+ }
139
+ // If `callback` throws, wait for the next mutation, interval, or timeout.
153
140
  } catch (error) {
154
141
  // Save the most recent callback error to reject the promise with it in the event of a timeout
155
142
  lastError = error;
156
143
  }
157
144
  }
158
-
159
145
  function handleTimeout() {
160
146
  let error;
161
-
162
147
  if (lastError) {
163
148
  error = lastError;
164
-
165
149
  if (stackTraceError) {
166
150
  (0, _errors.copyStackTrace)(error, stackTraceError);
167
151
  }
168
152
  } else {
169
153
  error = new Error('Timed out in waitFor.');
170
-
171
154
  if (stackTraceError) {
172
155
  (0, _errors.copyStackTrace)(error, stackTraceError);
173
156
  }
174
157
  }
175
-
176
158
  if (typeof onTimeout === 'function') {
177
159
  onTimeout(error);
178
160
  }
179
-
180
161
  onDone({
181
162
  type: 'error',
182
163
  error
@@ -184,7 +165,6 @@ function waitForInternal(expectation, {
184
165
  }
185
166
  });
186
167
  }
187
-
188
168
  async function waitFor(expectation, options) {
189
169
  // Being able to display a useful stack trace requires generating it before doing anything async
190
170
  const stackTraceError = new _errors.ErrorWithStack('STACK_TRACE_ERROR', waitFor);
@@ -192,27 +172,24 @@ async function waitFor(expectation, options) {
192
172
  stackTraceError,
193
173
  ...options
194
174
  };
195
-
196
175
  if ((0, _reactVersions.checkReactVersionAtLeast)(18, 0)) {
197
176
  const previousActEnvironment = (0, _act.getIsReactActEnvironment)();
198
177
  (0, _act.setReactActEnvironment)(false);
199
-
200
178
  try {
201
179
  return await waitForInternal(expectation, optionsWithStackTrace);
202
180
  } finally {
203
181
  (0, _act.setReactActEnvironment)(previousActEnvironment);
204
182
  }
205
183
  }
206
-
207
184
  if (!(0, _reactVersions.checkReactVersionAtLeast)(16, 9)) {
208
185
  return waitForInternal(expectation, optionsWithStackTrace);
209
186
  }
210
-
211
187
  let result;
212
188
  await (0, _act.default)(async () => {
213
189
  result = await waitForInternal(expectation, optionsWithStackTrace);
214
- }); // Either we have result or `waitFor` threw error
190
+ });
215
191
 
192
+ // Either we have result or `waitFor` threw error
216
193
  return result;
217
194
  }
218
195
  //# sourceMappingURL=waitFor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"waitFor.js","names":["DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","setTimeout","handleTimeout","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","jest","advanceTimersByTime","setImmediate","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace","checkReactVersionAtLeast","previousActEnvironment","getIsReactActEnvironment","setReactActEnvironment","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport act, { setReactActEnvironment, getIsReactActEnvironment } from './act';\nimport { getConfig } from './config';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (checkReactVersionAtLeast(18, 0)) {\n const previousActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(false);\n\n try {\n return await waitForInternal(expectation, optionsWithStackTrace);\n } finally {\n setReactActEnvironment(previousActEnvironment);\n }\n }\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAVA;AAYA,MAAMA,gBAAgB,GAAG,EAAzB;;AASA,SAASC,eAAT,CACEC,WADF,EAEE;EACEC,OAAO,GAAG,IAAAC,iBAAA,IAAYC,gBADxB;EAEEC,QAAQ,GAAGN,gBAFb;EAGEO,eAHF;EAIEC;AAJF,CAFF,EAQc;EACZ,IAAI,OAAON,WAAP,KAAuB,UAA3B,EAAuC;IACrC,MAAM,IAAIO,SAAJ,CAAc,+CAAd,CAAN;EACD,CAHW,CAKZ;;;EACA,OAAO,IAAIC,OAAJ,CAAY,OAAOC,OA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AAY;IACpBb,MAAM,GAAG,MAAMpC,eAAe,CAACC,WAAD,EAAc2C,qBAAd,CAA9B;EACD,CAFK,CAAN,CAtBY,CA0BZ;;EACA,OAAOR,MAAP;AACD"}
1
+ {"version":3,"file":"waitFor.js","names":["DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","handleTimeout","jest","advanceTimersByTime","setImmediate","setTimeout","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace","checkReactVersionAtLeast","previousActEnvironment","getIsReactActEnvironment","setReactActEnvironment","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport act, { setReactActEnvironment, getIsReactActEnvironment } from './act';\nimport { getConfig } from './config';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n let overallTimeoutTimer: NodeJS.Timeout | null = null;\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n handleTimeout();\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n if (overallTimeoutTimer) {\n clearTimeout(overallTimeoutTimer);\n }\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (checkReactVersionAtLeast(18, 0)) {\n const previousActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(false);\n\n try {\n return await waitForInternal(expectation, optionsWithStackTrace);\n } finally {\n setReactActEnvironment(previousActEnvironment);\n }\n }\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AAMA;AAA4D;AAAA;AAV5D;;AAYA,MAAMA,gBAAgB,GAAG,EAAE;AAS3B,SAASC,eAAe,CACtBC,WAAoB,EACpB;EACEC,OAAO,GAAG,IAAAC,iBAAS,GAAE,CAACC,gBAAgB;EACtCC,QAAQ,GAAGN,gBAAgB;EAC3BO,eAAe;EACfC;AACc,CAAC,EACL;EACZ,IAAI,OAAON,WAAW,KAAK,UAAU,EAAE;IACrC,MAAM,IAAIO,SAAS,CAAC,+CAA+C,CAAC;EACtE;;EAEA;EACA,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;IAC5C,IAAIC,SAAkB,EAAEC,UAAyC;IACjE,IAAIC,QAAQ,GAAG,KAAK;IACpB,IAAIC,aAAa,GAAG,MAAM;IAE1B,IAAIC,mBAA0C,GAAG,IAAI;IAErD,MAAMC,eAAe,GAAG,IAAAC,gCAAwB,GAAE;IAElD,IAAID,eAAe,EAAE;MACnBE,gBAAgB,EAAE;MAClB;MACA;MACA;MACA;MACA;MACA,IAAIC,iBAAiB,GAAGlB,OAAO;MAC/B,OAAO,CAACY,QAAQ,EAAE;QAChB,IAAI,CAAC,IAAAI,gCAAwB,GAAE,EAAE;UAC/B,MAAMG,KAAK,GAAG,IAAIC,KAAK,CACpB,kUAAiU,CACnU;UACD,IAAIhB,eAAe,EAAE;YACnB,IAAAiB,sBAAc,EAACF,KAAK,EAAEf,eAAe,CAAC;UACxC;UACAK,MAAM,CAACU,KAAK,CAAC;U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oB,OAAO,CACnCxC,WAAoB,EACpByC,OAAwB,EACZ;EACZ;EACA,MAAMpC,eAAe,GAAG,IAAIqC,sBAAc,CAAC,mBAAmB,EAAEF,OAAO,CAAC;EACxE,MAAMG,qBAAqB,GAAG;IAAEtC,eAAe;IAAE,GAAGoC;EAAQ,CAAC;EAE7D,IAAI,IAAAG,uCAAwB,EAAC,EAAE,EAAE,CAAC,CAAC,EAAE;IACnC,MAAMC,sBAAsB,GAAG,IAAAC,6BAAwB,GAAE;IACzD,IAAAC,2BAAsB,EAAC,KAAK,CAAC;IAE7B,IAAI;MACF,OAAO,MAAMhD,eAAe,CAACC,WAAW,EAAE2C,qBAAqB,CAAC;IAClE,CAAC,SAAS;MACR,IAAAI,2BAAsB,EAACF,sBAAsB,CAAC;IAChD;EACF;EAEA,IAAI,CAAC,IAAAD,uCAAwB,EAAC,EAAE,EAAE,CAAC,CAAC,EAAE;IACpC,OAAO7C,eAAe,CAACC,WAAW,EAAE2C,qBAAqB,CAAC;EAC5D;EAEA,IAAIR,MAAS;EAEb,MAAM,IAAAa,YAAG,EAAC,YAAY;IACpBb,MAAM,GAAG,MAAMpC,eAAe,CAACC,WAAW,EAAE2C,qBAAqB,CAAC;EACpE,CAAC,CAAC;;EAEF;EACA,OAAOR,MAAM;AACf"}
@@ -4,40 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = waitForElementToBeRemoved;
7
-
8
7
  var _waitFor = _interopRequireDefault(require("./waitFor"));
9
-
10
8
  var _errors = require("./helpers/errors");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  function isRemoved(result) {
15
11
  return !result || Array.isArray(result) && !result.length;
16
12
  }
17
-
18
13
  async function waitForElementToBeRemoved(expectation, options) {
19
14
  // Created here so we get a nice stacktrace
20
- const timeoutError = new _errors.ErrorWithStack('Timed out in waitForElementToBeRemoved.', waitForElementToBeRemoved); // Elements have to be present initally and then removed.
15
+ const timeoutError = new _errors.ErrorWithStack('Timed out in waitForElementToBeRemoved.', waitForElementToBeRemoved);
21
16
 
17
+ // Elements have to be present initally and then removed.
22
18
  const initialElements = expectation();
23
-
24
19
  if (isRemoved(initialElements)) {
25
20
  throw new _errors.ErrorWithStack('The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.', waitForElementToBeRemoved);
26
21
  }
27
-
28
22
  return (0, _waitFor.default)(() => {
29
23
  let result;
30
-
31
24
  try {
32
25
  result = expectation();
33
26
  } catch (error) {
34
27
  return initialElements;
35
28
  }
36
-
37
29
  if (!isRemoved(result)) {
38
30
  throw timeoutError;
39
31
  }
40
-
41
32
  return initialElements;
42
33
  }, options);
43
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"waitForElementToBeRemoved.js","names":["isRemoved","result","Array","isArray","length","waitForElementToBeRemoved","expectation","options","timeoutError","ErrorWithStack","initialElements","waitFor","error"],"sources":["../src/waitForElementToBeRemoved.ts"],"sourcesContent":["import waitFor from './waitFor';\nimport type { WaitForOptions } from './waitFor';\nimport { ErrorWithStack } from './helpers/errors';\n\nfunction isRemoved<T>(result: T): boolean {\n return !result || (Array.isArray(result) && !result.length);\n}\n\nexport default async function waitForElementToBeRemoved<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Created here so we get a nice stacktrace\n const timeoutError = new ErrorWithStack(\n 'Timed out in waitForElementToBeRemoved.',\n waitForElementToBeRemoved\n );\n\n // Elements have to be present initally and then removed.\n const initialElements = expectation();\n if (isRemoved(initialElements)) {\n throw new ErrorWithStack(\n 'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',\n waitForElementToBeRemoved\n );\n }\n\n return waitFor(() => {\n let result;\n try {\n result = expectation();\n } catch (error) {\n return initialElements;\n }\n\n if (!isRemoved(result)) {\n throw timeoutError;\n }\n\n return initialElements;\n }, options);\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAEA,SAASA,SAAT,CAAsBC,MAAtB,EAA0C;EACxC,OAAO,CAACA,MAAD,IAAYC,KAAK,CAACC,OAAN,CAAcF,MAAd,KAAyB,CAACA,MAAM,CAACG,MAApD;AACD;;AAEc,eAAeC,yBAAf,CACbC,WADa,EAEbC,OAFa,EAGD;EACZ;EACA,MAAMC,YAAY,GAAG,IAAIC,sBAAJ,CACnB,yCADmB,EAEnBJ,yBAFmB,CAArB,CAFY,CAOZ;;EACA,MAAMK,eAAe,GAAGJ,WAAW,EAAnC;;EACA,IAAIN,SAAS,CAACU,eAAD,CAAb,EAAgC;IAC9B,MAAM,IAAID,sBAAJ,CACJ,oKADI,EAEJJ,yBAFI,CAAN;EAID;;EAED,OAAO,IAAAM,gBAAA,EAAQ,MAAM;IACnB,IAAIV,MAAJ;;IACA,IAAI;MACFA,MAAM,GAAGK,WAAW,EAApB;IACD,CAFD,CAEE,OAAOM,KAAP,EAAc;MACd,OAAOF,eAAP;IACD;;IAED,IAAI,CAACV,SAAS,CAACC,MAAD,CAAd,EAAwB;MACtB,MAAMO,YAAN;IACD;;IAED,OAAOE,eAAP;EACD,CAbM,EAaJH,OAbI,CAAP;AAcD"}
1
+ {"version":3,"file":"waitForElementToBeRemoved.js","names":["isRemoved","result","Array","isArray","length","waitForElementToBeRemoved","expectation","options","timeoutError","ErrorWithStack","initialElements","waitFor","error"],"sources":["../src/waitForElementToBeRemoved.ts"],"sourcesContent":["import waitFor from './waitFor';\nimport type { WaitForOptions } from './waitFor';\nimport { ErrorWithStack } from './helpers/errors';\n\nfunction isRemoved<T>(result: T): boolean {\n return !result || (Array.isArray(result) && !result.length);\n}\n\nexport default async function waitForElementToBeRemoved<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Created here so we get a nice stacktrace\n const timeoutError = new ErrorWithStack(\n 'Timed out in waitForElementToBeRemoved.',\n waitForElementToBeRemoved\n );\n\n // Elements have to be present initally and then removed.\n const initialElements = expectation();\n if (isRemoved(initialElements)) {\n throw new ErrorWithStack(\n 'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',\n waitForElementToBeRemoved\n );\n }\n\n return waitFor(() => {\n let result;\n try {\n result = expectation();\n } catch (error) {\n return initialElements;\n }\n\n if (!isRemoved(result)) {\n throw timeoutError;\n }\n\n return initialElements;\n }, options);\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAAkD;AAElD,SAASA,SAAS,CAAIC,MAAS,EAAW;EACxC,OAAO,CAACA,MAAM,IAAKC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,IAAI,CAACA,MAAM,CAACG,MAAO;AAC7D;AAEe,eAAeC,yBAAyB,CACrDC,WAAoB,EACpBC,OAAwB,EACZ;EACZ;EACA,MAAMC,YAAY,GAAG,IAAIC,sBAAc,CACrC,yCAAyC,EACzCJ,yBAAyB,CAC1B;;EAED;EACA,MAAMK,eAAe,GAAGJ,WAAW,EAAE;EACrC,IAAIN,SAAS,CAACU,eAAe,CAAC,EAAE;IAC9B,MAAM,IAAID,sBAAc,CACtB,oKAAoK,EACpKJ,yBAAyB,CAC1B;EACH;EAEA,OAAO,IAAAM,gBAAO,EAAC,MAAM;IACnB,IAAIV,MAAM;IACV,IAAI;MACFA,MAAM,GAAGK,WAAW,EAAE;IACxB,CAAC,CAAC,OAAOM,KAAK,EAAE;MACd,OAAOF,eAAe;IACxB;IAEA,IAAI,CAACV,SAAS,CAACC,MAAM,CAAC,EAAE;MACtB,MAAMO,YAAY;IACpB;IAEA,OAAOE,eAAe;EACxB,CAAC,EAAEH,OAAO,CAAC;AACb"}