config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.runWithExpensiveErrorDiagnosticsDisabled = runWithExpensiveErrorDiagnosticsDisabled;
  6. exports.configure = configure;
  7. exports.getConfig = getConfig;
  8. exports.DEFAULT_IGNORE_TAGS = void 0;
  9. var _prettyDom = require("./pretty-dom");
  10. // It would be cleaner for this to live inside './queries', but
  11. // other parts of the code assume that all exports from
  12. // './queries' are query functions.
  13. let config = {
  14. testIdAttribute: 'data-testid',
  15. asyncUtilTimeout: 1000,
  16. // this is to support React's async `act` function.
  17. // forcing react-testing-library to wrap all async functions would've been
  18. // a total nightmare (consider wrapping every findBy* query and then also
  19. // updating `within` so those would be wrapped too. Total nightmare).
  20. // so we have this config option that's really only intended for
  21. // react-testing-library to use. For that reason, this feature will remain
  22. // undocumented.
  23. asyncWrapper: cb => cb(),
  24. eventWrapper: cb => cb(),
  25. // default value for the `hidden` option in `ByRole` queries
  26. defaultHidden: false,
  27. // showOriginalStackTrace flag to show the full error stack traces for async errors
  28. showOriginalStackTrace: false,
  29. // throw errors w/ suggestions for better queries. Opt in so off by default.
  30. throwSuggestions: false,
  31. // called when getBy* queries fail. (message, container) => Error
  32. getElementError(message, container) {
  33. const error = new Error([message, (0, _prettyDom.prettyDOM)(container)].filter(Boolean).join('\n\n'));
  34. error.name = 'TestingLibraryElementError';
  35. return error;
  36. },
  37. _disableExpensiveErrorDiagnostics: false,
  38. computedStyleSupportsPseudoElements: false
  39. };
  40. const DEFAULT_IGNORE_TAGS = 'script, style';
  41. exports.DEFAULT_IGNORE_TAGS = DEFAULT_IGNORE_TAGS;
  42. function runWithExpensiveErrorDiagnosticsDisabled(callback) {
  43. try {
  44. config._disableExpensiveErrorDiagnostics = true;
  45. return callback();
  46. } finally {
  47. config._disableExpensiveErrorDiagnostics = false;
  48. }
  49. }
  50. function configure(newConfig) {
  51. if (typeof newConfig === 'function') {
  52. // Pass the existing config out to the provided function
  53. // and accept a delta in return
  54. newConfig = newConfig(config);
  55. } // Merge the incoming config delta
  56. config = { ...config,
  57. ...newConfig
  58. };
  59. }
  60. function getConfig() {
  61. return config;
  62. }