Skip to content

Commit

Permalink
fix: add number support for matches (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvega91 authored Jan 4, 2021
1 parent accb6cc commit ec1b642
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ function fuzzyMatches(

const normalizedText = normalizer(textToMatch)

if (typeof matcher === 'string') {
return normalizedText.toLowerCase().includes(matcher.toLowerCase())
if (typeof matcher === 'string' || typeof matcher === 'number') {
return normalizedText
.toLowerCase()
.includes(matcher.toString().toLowerCase())
} else if (typeof matcher === 'function') {
return matcher(normalizedText, node)
} else {
Expand Down
2 changes: 1 addition & 1 deletion types/matches.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type MatcherFunction = (
content: string,
element: Nullish<Element>,
) => boolean
export type Matcher = MatcherFunction | RegExp | string
export type Matcher = MatcherFunction | RegExp | string | number

// Get autocomplete for ARIARole union types, while still supporting another string
// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972
Expand Down
6 changes: 5 additions & 1 deletion types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "../tsconfig.json"
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {"@testing-library/dom": ["."]}
}
}

0 comments on commit ec1b642

Please sign in to comment.