MCPcopy
hub / github.com/testing-library/dom-testing-library / makeNormalizer

Function makeNormalizer

src/matches.ts:89–112  ·  view source on GitHub ↗

* Constructs a normalizer to pass to functions in matches.js * @param {boolean|undefined} trim The user-specified value for `trim`, without * any defaulting having been applied * @param {boolean|undefined} collapseWhitespace The user-specified value for * `collapseWhitespace`, without any defaul

({
  trim,
  collapseWhitespace,
  normalizer,
}: NormalizerOptions)

Source from the content-addressed store, hash-verified

87 */
88
89function makeNormalizer({
90 trim,
91 collapseWhitespace,
92 normalizer,
93}: NormalizerOptions) {
94 if (!normalizer) {
95 // No custom normalizer specified. Just use default.
96 return getDefaultNormalizer({trim, collapseWhitespace})
97 }
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
112}
113
114function matchRegExp(matcher: RegExp, text: string) {
115 const match = matcher.test(text)

Callers 7

queryAllByAttributeFunction · 0.90
queryAllByTextFunction · 0.85
getMissingErrorFunction · 0.85
queryAllLabelsByTextFunction · 0.85
queryAllByLabelTextFunction · 0.85
queryAllByTitleFunction · 0.85
queryAllByDisplayValueFunction · 0.85

Calls 1

getDefaultNormalizerFunction · 0.85

Tested by

no test coverage detected