alt-text.js 1.5 KB

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.queryByAltText = exports.queryAllByAltText = exports.getByAltText = exports.getAllByAltText = exports.findByAltText = exports.findAllByAltText = void 0;
  6. var _queryHelpers = require("../query-helpers");
  7. var _helpers = require("../helpers");
  8. var _allUtils = require("./all-utils");
  9. // Valid tags are img, input, area and custom elements
  10. const VALID_TAG_REGEXP = /^(img|input|area|.+-.+)$/i;
  11. const queryAllByAltText = (container, alt, options = {}) => {
  12. (0, _helpers.checkContainerType)(container);
  13. return (0, _queryHelpers.queryAllByAttribute)('alt', container, alt, options).filter(node => VALID_TAG_REGEXP.test(node.tagName));
  14. };
  15. const getMultipleError = (c, alt) => `Found multiple elements with the alt text: ${alt}`;
  16. const getMissingError = (c, alt) => `Unable to find an element with the alt text: ${alt}`;
  17. const queryAllByAltTextWithSuggestions = (0, _queryHelpers.wrapAllByQueryWithSuggestion)(queryAllByAltText, queryAllByAltText.name, 'queryAll');
  18. exports.queryAllByAltText = queryAllByAltTextWithSuggestions;
  19. const [queryByAltText, getAllByAltText, getByAltText, findAllByAltText, findByAltText] = (0, _allUtils.buildQueries)(queryAllByAltText, getMultipleError, getMissingError);
  20. exports.findByAltText = findByAltText;
  21. exports.findAllByAltText = findAllByAltText;
  22. exports.getByAltText = getByAltText;
  23. exports.getAllByAltText = getAllByAltText;
  24. exports.queryByAltText = queryByAltText;