Skip to content

Commit

Permalink
Apply normalizer treatment to queryAllByDisplayValue
Browse files Browse the repository at this point in the history
  • Loading branch information
RoystonS committed Dec 12, 2018
1 parent c441145 commit c51406d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/__tests__/text-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ cases(
dom: `<input value="User ${LRM}name" />`,
queryFn: 'queryAllByValue',
},
queryAllByDisplayValue: {
dom: `<input value="User ${LRM}name" />`,
queryFn: 'queryAllByDisplayValue',
},
queryAllByRole: {
dom: `<input role="User ${LRM}name" />`,
queryFn: 'queryAllByRole',
Expand Down
8 changes: 4 additions & 4 deletions src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,21 @@ function queryByAltText(...args) {
function queryAllByDisplayValue(
container,
value,
{exact = true, collapseWhitespace = true, trim = true} = {},
{exact = true, collapseWhitespace, trim, normalizer} = {},
) {
const matcher = exact ? matches : fuzzyMatches
const matchOpts = {collapseWhitespace, trim}
const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer})
return Array.from(container.querySelectorAll(`input,textarea,select`)).filter(
node => {
if (node.tagName === 'SELECT') {
const selectedOptions = Array.from(node.options).filter(
option => option.selected,
)
return selectedOptions.some(optionNode =>
matcher(getNodeText(optionNode), optionNode, value, matchOpts),
matcher(getNodeText(optionNode), optionNode, value, matchNormalizer),
)
} else {
return matcher(node.value, node, value, matchOpts)
return matcher(node.value, node, value, matchNormalizer)
}
},
)
Expand Down

0 comments on commit c51406d

Please sign in to comment.