Skip to content

Commit

Permalink
fix(textMatch): if the textToMatch is not a string then it wont match
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Mar 29, 2018
1 parent e9b603d commit 9792568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ test('totally empty label', () => {

test('get element by its alt text', () => {
const {getByAltText} = render(
<img alt="finding nemo poster" src="/finding-nemo.png" />,
<div>
<input data-info="no alt here" />
<img alt="finding nemo poster" src="/finding-nemo.png" />
</div>,
)
expect(getByAltText(/fin.*nem.*poster$/i).src).toBe('/finding-nemo.png')
})
Expand Down
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//eslint-disable-next-line import/prefer-default-export
export function matches(textToMatch, node, matcher) {
if (typeof textToMatch !== 'string') {
return false
}
if (typeof matcher === 'string') {
return textToMatch.toLowerCase().includes(matcher.toLowerCase())
} else if (typeof matcher === 'function') {
Expand Down

0 comments on commit 9792568

Please sign in to comment.