From ec1b642ba6069cbe5a85db649a939ff00d434343 Mon Sep 17 00:00:00 2001 From: Marco Moretti Date: Mon, 4 Jan 2021 09:39:15 +0100 Subject: [PATCH] fix: add number support for matches (#856) --- src/matches.ts | 6 ++++-- types/matches.d.ts | 2 +- types/tsconfig.json | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/matches.ts b/src/matches.ts index 5aecb416..5e27ad3e 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -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 { diff --git a/types/matches.d.ts b/types/matches.d.ts index 03f9a4b8..2d05d4ab 100644 --- a/types/matches.d.ts +++ b/types/matches.d.ts @@ -6,7 +6,7 @@ export type MatcherFunction = ( content: string, element: Nullish, ) => 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 diff --git a/types/tsconfig.json b/types/tsconfig.json index 3c43903c..315b2549 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -1,3 +1,7 @@ { - "extends": "../tsconfig.json" + "extends": "../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "paths": {"@testing-library/dom": ["."]} + } }