@testing-library/dom
Advanced tools
Comparing version 9.0.0-alpha.1 to 9.0.0-alpha.2
@@ -23,2 +23,3 @@ "use strict"; | ||
// modern timers | ||
// eslint-disable-next-line prefer-object-has-own -- not supported by our support matrix | ||
Object.prototype.hasOwnProperty.call(setTimeout, 'clock') | ||
@@ -25,0 +26,0 @@ ); |
@@ -62,13 +62,21 @@ "use strict"; | ||
labelList.filter(label => Boolean(label.formControl)).forEach(label => { | ||
if (matcher(label.content, label.formControl, text, matchNormalizer) && label.formControl) labelledElements.push(label.formControl); | ||
if (matcher(label.content, label.formControl, text, matchNormalizer) && label.formControl) { | ||
labelledElements.push(label.formControl); | ||
} | ||
}); | ||
const labelsValue = labelList.filter(label => Boolean(label.content)).map(label => label.content); | ||
if (matcher(labelsValue.join(' '), labelledElement, text, matchNormalizer)) labelledElements.push(labelledElement); | ||
if (matcher(labelsValue.join(' '), labelledElement, text, matchNormalizer)) { | ||
labelledElements.push(labelledElement); | ||
} | ||
if (labelsValue.length > 1) { | ||
labelsValue.forEach((labelValue, index) => { | ||
if (matcher(labelValue, labelledElement, text, matchNormalizer)) labelledElements.push(labelledElement); | ||
if (matcher(labelValue, labelledElement, text, matchNormalizer)) { | ||
labelledElements.push(labelledElement); | ||
} | ||
const labelsFiltered = [...labelsValue]; | ||
labelsFiltered.splice(index, 1); | ||
if (labelsFiltered.length > 1) { | ||
if (matcher(labelsFiltered.join(' '), labelledElement, text, matchNormalizer)) labelledElements.push(labelledElement); | ||
if (matcher(labelsFiltered.join(' '), labelledElement, text, matchNormalizer)) { | ||
labelledElements.push(labelledElement); | ||
} | ||
} | ||
@@ -75,0 +83,0 @@ }); |
@@ -13,10 +13,6 @@ "use strict"; | ||
var _allUtils = require("./all-utils"); | ||
function queryAllByRole(container, role, { | ||
exact = true, | ||
collapseWhitespace, | ||
const queryAllByRole = (container, role, { | ||
hidden = (0, _allUtils.getConfig)().defaultHidden, | ||
name, | ||
description, | ||
trim, | ||
normalizer, | ||
queryFallbacks = false, | ||
@@ -29,10 +25,4 @@ selected, | ||
expanded | ||
} = {}) { | ||
} = {}) => { | ||
(0, _helpers.checkContainerType)(container); | ||
const matcher = exact ? _allUtils.matches : _allUtils.fuzzyMatches; | ||
const matchNormalizer = (0, _allUtils.makeNormalizer)({ | ||
collapseWhitespace, | ||
trim, | ||
normalizer | ||
}); | ||
if (selected !== undefined) { | ||
@@ -91,3 +81,3 @@ var _allRoles$get; | ||
// Only query elements that can be matched by the following filters | ||
makeRoleSelector(role, exact, normalizer ? matchNormalizer : undefined))).filter(node => { | ||
makeRoleSelector(role))).filter(node => { | ||
const isRoleSpecifiedExplicitly = node.hasAttribute('role'); | ||
@@ -97,14 +87,12 @@ if (isRoleSpecifiedExplicitly) { | ||
if (queryFallbacks) { | ||
return roleValue.split(' ').filter(Boolean).some(text => matcher(text, node, role, matchNormalizer)); | ||
return roleValue.split(' ').filter(Boolean).some(roleAttributeToken => roleAttributeToken === role); | ||
} | ||
// if a custom normalizer is passed then let normalizer handle the role value | ||
if (normalizer) { | ||
return matcher(roleValue, node, role, matchNormalizer); | ||
} | ||
// other wise only send the first word to match | ||
const [firstWord] = roleValue.split(' '); | ||
return matcher(firstWord, node, role, matchNormalizer); | ||
// other wise only send the first token to match | ||
const [firstRoleAttributeToken] = roleValue.split(' '); | ||
return firstRoleAttributeToken === role; | ||
} | ||
const implicitRoles = (0, _roleHelpers.getImplicitAriaRoles)(node); | ||
return implicitRoles.some(implicitRole => matcher(implicitRole, node, role, matchNormalizer)); | ||
return implicitRoles.some(implicitRole => { | ||
return implicitRole === role; | ||
}); | ||
}).filter(element => { | ||
@@ -152,9 +140,5 @@ if (selected !== undefined) { | ||
}); | ||
} | ||
function makeRoleSelector(role, exact, customNormalizer) { | ||
if (typeof role !== 'string') { | ||
// For non-string role parameters we can not determine the implicitRoleSelectors. | ||
return '*'; | ||
} | ||
const explicitRoleSelector = exact && !customNormalizer ? `*[role~="${role}"]` : '*[role]'; | ||
}; | ||
function makeRoleSelector(role) { | ||
const explicitRoleSelector = `*[role~="${role}"]`; | ||
const roleRelations = _ariaQuery.roleElements.get(role) ?? new Set(); | ||
@@ -161,0 +145,0 @@ const implicitRoleSelectors = new Set(Array.from(roleRelations).map(({ |
{ | ||
"name": "@testing-library/dom", | ||
"version": "9.0.0-alpha.1", | ||
"version": "9.0.0-alpha.2", | ||
"description": "Simple and complete DOM testing utilities that encourage good testing practices.", | ||
@@ -77,4 +77,4 @@ "main": "dist/index.js", | ||
"jest-watch-select-projects": "^2.0.0", | ||
"jsdom": "^16.4.0", | ||
"kcd-scripts": "^11.0.0", | ||
"jsdom": "20.0.0", | ||
"kcd-scripts": "^13.0.0", | ||
"typescript": "^4.1.2" | ||
@@ -87,2 +87,5 @@ }, | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2020 | ||
}, | ||
"rules": { | ||
@@ -92,2 +95,3 @@ "@typescript-eslint/prefer-optional-chain": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off", | ||
"@typescript-eslint/prefer-includes": "off", | ||
@@ -94,0 +98,0 @@ "import/prefer-default-export": "off", |
@@ -10,4 +10,4 @@ import {ARIARole} from 'aria-query' | ||
// Get autocomplete for ARIARole union types, while still supporting another string | ||
// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972 | ||
export type ByRoleMatcher = ARIARole | MatcherFunction | {} | ||
// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939 | ||
export type ByRoleMatcher = ARIARole | (string & {}) | ||
@@ -14,0 +14,0 @@ export type NormalizerFn = (text: string) => string |
@@ -69,3 +69,5 @@ import {ByRoleMatcher, Matcher, MatcherOptions} from './matches' | ||
export interface ByRoleOptions extends MatcherOptions { | ||
export interface ByRoleOptions { | ||
/** suppress suggestions for a specific query */ | ||
suggest?: boolean | ||
/** | ||
@@ -72,0 +74,0 @@ * If true includes elements in the query set that are usually excluded from |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
396
2919220
25037