Skip to content

Commit ed34a69

Browse files
committed
chore: use default arg value for normalizer
1 parent 864155a commit ed34a69

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

src/helpers/byDisplayValue.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import { getDefaultNormalizer, matches } from '../matches';
2+
import { matches } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import { filterNodeByType } from './filterNodeByType';
@@ -14,14 +14,13 @@ const getTextInputNodeByDisplayValue = (
1414
try {
1515
const { TextInput } = require('react-native');
1616
const { exact, normalizer } = options;
17-
const normalizerFn = normalizer ?? getDefaultNormalizer();
1817
const nodeValue =
1918
node.props.value !== undefined
2019
? node.props.value
2120
: node.props.defaultValue;
2221
return (
2322
filterNodeByType(node, TextInput) &&
24-
matches(value, nodeValue, normalizerFn, exact)
23+
matches(value, nodeValue, normalizer, exact)
2524
);
2625
} catch (error) {
2726
throw createLibraryNotSupportedError(error);

src/helpers/byPlaceholderText.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import { getDefaultNormalizer, matches } from '../matches';
2+
import { matches } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import { filterNodeByType } from './filterNodeByType';
@@ -14,10 +14,9 @@ const getTextInputNodeByPlaceholderText = (
1414
try {
1515
const { TextInput } = require('react-native');
1616
const { exact, normalizer } = options;
17-
const normalizerFn = normalizer ?? getDefaultNormalizer();
1817
return (
1918
filterNodeByType(node, TextInput) &&
20-
matches(placeholder, node.props.placeholder, normalizerFn, exact)
19+
matches(placeholder, node.props.placeholder, normalizer, exact)
2120
);
2221
} catch (error) {
2322
throw createLibraryNotSupportedError(error);

src/helpers/byTestId.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// @flow
2-
import { getDefaultNormalizer, matches } from '../matches';
2+
import { matches } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import type { TextMatchOptions } from './byText';
66

77
const getNodeByTestId = (node, testID, options?: TextMatchOptions = {}) => {
88
const { exact, normalizer } = options;
9-
const normalizerFn = normalizer ?? getDefaultNormalizer();
10-
11-
return matches(testID, node.props.testID, normalizerFn, exact);
9+
return matches(testID, node.props.testID, normalizer, exact);
1210
};
1311

1412
const queryAllByTestId = (

src/helpers/byText.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import * as React from 'react';
3-
import { getDefaultNormalizer, matches } from '../matches';
3+
import { matches } from '../matches';
44
import type { NormalizerFn } from '../matches';
55
import { makeQueries } from './makeQueries';
66
import type { Queries } from './makeQueries';
@@ -54,8 +54,7 @@ const getNodeByText = (
5454
if (textChildren) {
5555
const textToTest = textChildren.join('');
5656
const { exact, normalizer } = options;
57-
const normalizerFn = normalizer ?? getDefaultNormalizer();
58-
return matches(text, textToTest, normalizerFn, exact);
57+
return matches(text, textToTest, normalizer, exact);
5958
}
6059
}
6160
return false;

src/matches.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @flow
22
export type NormalizerFn = (textToNormalize: string) => string;
33

4-
function matches(
4+
export function matches(
55
matcher: string | RegExp,
66
text: string,
7-
normalizer: NormalizerFn,
7+
normalizer?: NormalizerFn = getDefaultNormalizer(),
88
exact?: boolean = true
99
): boolean {
1010
if (typeof text !== 'string') {
@@ -26,7 +26,7 @@ type NormalizerConfig = {
2626
collapseWhitespace?: boolean,
2727
};
2828

29-
function getDefaultNormalizer({
29+
export function getDefaultNormalizer({
3030
trim = true,
3131
collapseWhitespace = true,
3232
}: NormalizerConfig = {}): NormalizerFn {
@@ -39,5 +39,3 @@ function getDefaultNormalizer({
3939
return normalizedText;
4040
};
4141
}
42-
43-
export { matches, getDefaultNormalizer };

0 commit comments

Comments
 (0)