Skip to content

Commit 30bd614

Browse files
authored
Merge pull request #1102 from testing-library/refactor-early-return
refactor: Leverage early return
2 parents 7f5d421 + 02ac966 commit 30bd614

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/matches.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,24 @@ function makeNormalizer({
9191
collapseWhitespace,
9292
normalizer,
9393
}: NormalizerOptions) {
94-
if (normalizer) {
95-
// User has specified a custom normalizer
96-
if (
97-
typeof trim !== 'undefined' ||
98-
typeof collapseWhitespace !== 'undefined'
99-
) {
100-
// They've also specified a value for trim or collapseWhitespace
101-
throw new Error(
102-
'trim and collapseWhitespace are not supported with a normalizer. ' +
103-
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
104-
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
105-
)
106-
}
107-
108-
return normalizer
109-
} else {
94+
if (!normalizer) {
11095
// No custom normalizer specified. Just use default.
11196
return getDefaultNormalizer({trim, collapseWhitespace})
11297
}
98+
99+
if (
100+
typeof trim !== 'undefined' ||
101+
typeof collapseWhitespace !== 'undefined'
102+
) {
103+
// They've also specified a value for trim or collapseWhitespace
104+
throw new Error(
105+
'trim and collapseWhitespace are not supported with a normalizer. ' +
106+
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
107+
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
108+
)
109+
}
110+
111+
return normalizer
113112
}
114113

115114
export {fuzzyMatches, matches, getDefaultNormalizer, makeNormalizer}

0 commit comments

Comments
 (0)