1- function assertNotNullOrUndefined ( matcher ) {
2- if ( matcher == null ) {
1+ import {
2+ Matcher ,
3+ NormalizerFn ,
4+ NormalizerOptions ,
5+ DefaultNormalizerOptions ,
6+ } from '../types'
7+
8+ type Nullish < T > = T | null | undefined
9+
10+ function assertNotNullOrUndefined < T > (
11+ matcher : T ,
12+ ) : asserts matcher is NonNullable < T > {
13+ if ( matcher === null || matcher === undefined ) {
314 throw new Error (
15+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- implicitly converting `T` to `string`
416 `It looks like ${ matcher } was passed instead of a matcher. Did you do something like getByText(${ matcher } )?` ,
517 )
618 }
719}
820
9- function fuzzyMatches ( textToMatch , node , matcher , normalizer ) {
21+ function fuzzyMatches (
22+ textToMatch : Nullish < string > ,
23+ node : Nullish < Element > ,
24+ matcher : Nullish < Matcher > ,
25+ normalizer : NormalizerFn ,
26+ ) {
1027 if ( typeof textToMatch !== 'string' ) {
1128 return false
1229 }
13-
1430 assertNotNullOrUndefined ( matcher )
1531
1632 const normalizedText = normalizer ( textToMatch )
33+
1734 if ( typeof matcher === 'string' ) {
1835 return normalizedText . toLowerCase ( ) . includes ( matcher . toLowerCase ( ) )
1936 } else if ( typeof matcher === 'function' ) {
@@ -23,7 +40,12 @@ function fuzzyMatches(textToMatch, node, matcher, normalizer) {
2340 }
2441}
2542
26- function matches ( textToMatch , node , matcher , normalizer ) {
43+ function matches (
44+ textToMatch : Nullish < string > ,
45+ node : Nullish < Element > ,
46+ matcher : Nullish < Matcher > ,
47+ normalizer : NormalizerFn ,
48+ ) {
2749 if ( typeof textToMatch !== 'string' ) {
2850 return false
2951 }
@@ -40,7 +62,10 @@ function matches(textToMatch, node, matcher, normalizer) {
4062 }
4163}
4264
43- function getDefaultNormalizer ( { trim = true , collapseWhitespace = true } = { } ) {
65+ function getDefaultNormalizer ( {
66+ trim = true ,
67+ collapseWhitespace = true ,
68+ } : DefaultNormalizerOptions = { } ) : NormalizerFn {
4469 return text => {
4570 let normalizedText = text
4671 normalizedText = trim ? normalizedText . trim ( ) : normalizedText
@@ -60,7 +85,12 @@ function getDefaultNormalizer({trim = true, collapseWhitespace = true} = {}) {
6085 * @param {Function|undefined } normalizer The user-specified normalizer
6186 * @returns {Function } A normalizer
6287 */
63- function makeNormalizer ( { trim, collapseWhitespace, normalizer} ) {
88+
89+ function makeNormalizer ( {
90+ trim,
91+ collapseWhitespace,
92+ normalizer,
93+ } : NormalizerOptions ) {
6494 if ( normalizer ) {
6595 // User has specified a custom normalizer
6696 if (
0 commit comments