Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add number support for matches #856

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": ["."]}
}
nickserv marked this conversation as resolved.
Show resolved Hide resolved
}