wait-for-element.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.waitForElement = waitForElement;
  6. var _waitFor = require("./wait-for");
  7. let hasWarned = false; // deprecated... TODO: remove this method. People should use a find* query or
  8. // wait instead the reasoning is that this doesn't really do anything useful
  9. // that you can't get from using find* or wait.
  10. async function waitForElement(callback, options) {
  11. if (!hasWarned) {
  12. hasWarned = true;
  13. console.warn(`\`waitForElement\` has been deprecated. Use a \`find*\` query (preferred: https://testing-library.com/docs/dom-testing-library/api-queries#findby) or use \`waitFor\` instead: https://testing-library.com/docs/dom-testing-library/api-async#waitfor`);
  14. }
  15. if (!callback) {
  16. throw new Error('waitForElement requires a callback as the first parameter');
  17. }
  18. return (0, _waitFor.waitFor)(() => {
  19. const result = callback();
  20. if (!result) {
  21. throw new Error('Timed out in waitForElement.');
  22. }
  23. return result;
  24. }, options);
  25. }
  26. /*
  27. eslint
  28. require-await: "off"
  29. */