You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.5 KiB
25 lines
1.5 KiB
2 years ago
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.queryByAltText = exports.queryAllByAltText = exports.getByAltText = exports.getAllByAltText = exports.findByAltText = exports.findAllByAltText = void 0;
|
||
|
var _queryHelpers = require("../query-helpers");
|
||
|
var _helpers = require("../helpers");
|
||
|
var _allUtils = require("./all-utils");
|
||
|
// Valid tags are img, input, area and custom elements
|
||
|
const VALID_TAG_REGEXP = /^(img|input|area|.+-.+)$/i;
|
||
|
const queryAllByAltText = (container, alt, options = {}) => {
|
||
|
(0, _helpers.checkContainerType)(container);
|
||
|
return (0, _queryHelpers.queryAllByAttribute)('alt', container, alt, options).filter(node => VALID_TAG_REGEXP.test(node.tagName));
|
||
|
};
|
||
|
const getMultipleError = (c, alt) => `Found multiple elements with the alt text: ${alt}`;
|
||
|
const getMissingError = (c, alt) => `Unable to find an element with the alt text: ${alt}`;
|
||
|
const queryAllByAltTextWithSuggestions = (0, _queryHelpers.wrapAllByQueryWithSuggestion)(queryAllByAltText, queryAllByAltText.name, 'queryAll');
|
||
|
exports.queryAllByAltText = queryAllByAltTextWithSuggestions;
|
||
|
const [queryByAltText, getAllByAltText, getByAltText, findAllByAltText, findByAltText] = (0, _allUtils.buildQueries)(queryAllByAltText, getMultipleError, getMissingError);
|
||
|
exports.findByAltText = findByAltText;
|
||
|
exports.findAllByAltText = findAllByAltText;
|
||
|
exports.getByAltText = getByAltText;
|
||
|
exports.getAllByAltText = getAllByAltText;
|
||
|
exports.queryByAltText = queryByAltText;
|