test-id.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.findByTestId = exports.findAllByTestId = exports.getAllByTestId = exports.getByTestId = exports.queryAllByTestId = exports.queryByTestId = void 0;
  6. var _helpers = require("../helpers");
  7. var _queryHelpers = require("../query-helpers");
  8. var _allUtils = require("./all-utils");
  9. const getTestIdAttribute = () => (0, _allUtils.getConfig)().testIdAttribute;
  10. const queryAllByTestId = (...args) => {
  11. (0, _helpers.checkContainerType)(args[0]); // TODO: Remove ignore after `queryAllByAttribute` will be moved to TS
  12. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  13. // @ts-expect-error
  14. return (0, _allUtils.queryAllByAttribute)(getTestIdAttribute(), ...args);
  15. };
  16. const getMultipleError = (c, id) => `Found multiple elements by: [${getTestIdAttribute()}="${id}"]`;
  17. const getMissingError = (c, id) => `Unable to find an element by: [${getTestIdAttribute()}="${id}"]`;
  18. const queryAllByTestIdWithSuggestions = (0, _queryHelpers.wrapAllByQueryWithSuggestion)(queryAllByTestId, queryAllByTestId.name, 'queryAll');
  19. exports.queryAllByTestId = queryAllByTestIdWithSuggestions;
  20. const [queryByTestId, getAllByTestId, getByTestId, findAllByTestId, findByTestId] = (0, _allUtils.buildQueries)(queryAllByTestId, getMultipleError, getMissingError);
  21. exports.findByTestId = findByTestId;
  22. exports.findAllByTestId = findAllByTestId;
  23. exports.getByTestId = getByTestId;
  24. exports.getAllByTestId = getAllByTestId;
  25. exports.queryByTestId = queryByTestId;