@testing-library/react-native 8.0.0 → 9.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,27 +5,33 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.queryByDisplayValue = exports.queryAllByDisplayValue = exports.getByDisplayValue = exports.getAllByDisplayValue = exports.findByDisplayValue = exports.findAllByDisplayValue = void 0;
7
7
 
8
+ var _matches = require("../matches");
9
+
8
10
  var _makeQueries = require("./makeQueries");
9
11
 
10
12
  var _filterNodeByType = require("./filterNodeByType");
11
13
 
12
14
  var _errors = require("./errors");
13
15
 
14
- const getTextInputNodeByDisplayValue = (node, value) => {
16
+ const getTextInputNodeByDisplayValue = (node, value, options = {}) => {
15
17
  try {
16
18
  const {
17
19
  TextInput
18
20
  } = require('react-native');
19
21
 
22
+ const {
23
+ exact,
24
+ normalizer
25
+ } = options;
20
26
  const nodeValue = node.props.value !== undefined ? node.props.value : node.props.defaultValue;
21
- return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (typeof value === 'string' ? value === nodeValue : value.test(nodeValue));
27
+ return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (0, _matches.matches)(value, nodeValue, normalizer, exact);
22
28
  } catch (error) {
23
29
  throw (0, _errors.createLibraryNotSupportedError)(error);
24
30
  }
25
31
  };
26
32
 
27
- const queryAllByDisplayValue = instance => function queryAllByDisplayValueFn(displayValue) {
28
- return instance.findAll(node => getTextInputNodeByDisplayValue(node, displayValue));
33
+ const queryAllByDisplayValue = instance => function queryAllByDisplayValueFn(displayValue, queryOptions) {
34
+ return instance.findAll(node => getTextInputNodeByDisplayValue(node, displayValue, queryOptions));
29
35
  };
30
36
 
31
37
  exports.queryAllByDisplayValue = queryAllByDisplayValue;
@@ -1,19 +1,26 @@
1
1
  // @flow
2
+ import { matches } from '../matches';
2
3
  import { makeQueries } from './makeQueries';
3
4
  import type { Queries } from './makeQueries';
4
5
  import { filterNodeByType } from './filterNodeByType';
5
6
  import { createLibraryNotSupportedError } from './errors';
7
+ import type { TextMatchOptions } from './byText';
6
8
 
7
- const getTextInputNodeByDisplayValue = (node, value) => {
9
+ const getTextInputNodeByDisplayValue = (
10
+ node,
11
+ value,
12
+ options?: TextMatchOptions = {}
13
+ ) => {
8
14
  try {
9
15
  const { TextInput } = require('react-native');
16
+ const { exact, normalizer } = options;
10
17
  const nodeValue =
11
18
  node.props.value !== undefined
12
19
  ? node.props.value
13
20
  : node.props.defaultValue;
14
21
  return (
15
22
  filterNodeByType(node, TextInput) &&
16
- (typeof value === 'string' ? value === nodeValue : value.test(nodeValue))
23
+ matches(value, nodeValue, normalizer, exact)
17
24
  );
18
25
  } catch (error) {
19
26
  throw createLibraryNotSupportedError(error);
@@ -22,10 +29,13 @@ const getTextInputNodeByDisplayValue = (node, value) => {
22
29
 
23
30
  const queryAllByDisplayValue = (
24
31
  instance: ReactTestInstance
25
- ): ((displayValue: string | RegExp) => Array<ReactTestInstance>) =>
26
- function queryAllByDisplayValueFn(displayValue) {
32
+ ): ((
33
+ displayValue: string | RegExp,
34
+ queryOptions?: TextMatchOptions
35
+ ) => Array<ReactTestInstance>) =>
36
+ function queryAllByDisplayValueFn(displayValue, queryOptions) {
27
37
  return instance.findAll((node) =>
28
- getTextInputNodeByDisplayValue(node, displayValue)
38
+ getTextInputNodeByDisplayValue(node, displayValue, queryOptions)
29
39
  );
30
40
  };
31
41
 
@@ -5,26 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.queryByPlaceholderText = exports.queryAllByPlaceholderText = exports.getByPlaceholderText = exports.getAllByPlaceholderText = exports.findByPlaceholderText = exports.findAllByPlaceholderText = void 0;
7
7
 
8
+ var _matches = require("../matches");
9
+
8
10
  var _makeQueries = require("./makeQueries");
9
11
 
10
12
  var _filterNodeByType = require("./filterNodeByType");
11
13
 
12
14
  var _errors = require("./errors");
13
15
 
14
- const getTextInputNodeByPlaceholderText = (node, placeholder) => {
16
+ const getTextInputNodeByPlaceholderText = (node, placeholder, options = {}) => {
15
17
  try {
16
18
  const {
17
19
  TextInput
18
20
  } = require('react-native');
19
21
 
20
- return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (typeof placeholder === 'string' ? placeholder === node.props.placeholder : placeholder.test(node.props.placeholder));
22
+ const {
23
+ exact,
24
+ normalizer
25
+ } = options;
26
+ return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (0, _matches.matches)(placeholder, node.props.placeholder, normalizer, exact);
21
27
  } catch (error) {
22
28
  throw (0, _errors.createLibraryNotSupportedError)(error);
23
29
  }
24
30
  };
25
31
 
26
- const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(placeholder) {
27
- return instance.findAll(node => getTextInputNodeByPlaceholderText(node, placeholder));
32
+ const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(placeholder, queryOptions) {
33
+ return instance.findAll(node => getTextInputNodeByPlaceholderText(node, placeholder, queryOptions));
28
34
  };
29
35
 
30
36
  exports.queryAllByPlaceholderText = queryAllByPlaceholderText;
@@ -1,17 +1,22 @@
1
1
  // @flow
2
+ import { matches } from '../matches';
2
3
  import { makeQueries } from './makeQueries';
3
4
  import type { Queries } from './makeQueries';
4
5
  import { filterNodeByType } from './filterNodeByType';
5
6
  import { createLibraryNotSupportedError } from './errors';
7
+ import type { TextMatchOptions } from './byText';
6
8
 
7
- const getTextInputNodeByPlaceholderText = (node, placeholder) => {
9
+ const getTextInputNodeByPlaceholderText = (
10
+ node,
11
+ placeholder,
12
+ options?: TextMatchOptions = {}
13
+ ) => {
8
14
  try {
9
15
  const { TextInput } = require('react-native');
16
+ const { exact, normalizer } = options;
10
17
  return (
11
18
  filterNodeByType(node, TextInput) &&
12
- (typeof placeholder === 'string'
13
- ? placeholder === node.props.placeholder
14
- : placeholder.test(node.props.placeholder))
19
+ matches(placeholder, node.props.placeholder, normalizer, exact)
15
20
  );
16
21
  } catch (error) {
17
22
  throw createLibraryNotSupportedError(error);
@@ -20,10 +25,13 @@ const getTextInputNodeByPlaceholderText = (node, placeholder) => {
20
25
 
21
26
  const queryAllByPlaceholderText = (
22
27
  instance: ReactTestInstance
23
- ): ((placeholder: string | RegExp) => Array<ReactTestInstance>) =>
24
- function queryAllByPlaceholderFn(placeholder) {
28
+ ): ((
29
+ placeholder: string | RegExp,
30
+ queryOptions?: TextMatchOptions
31
+ ) => Array<ReactTestInstance>) =>
32
+ function queryAllByPlaceholderFn(placeholder, queryOptions) {
25
33
  return instance.findAll((node) =>
26
- getTextInputNodeByPlaceholderText(node, placeholder)
34
+ getTextInputNodeByPlaceholderText(node, placeholder, queryOptions)
27
35
  );
28
36
  };
29
37
 
@@ -5,14 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.queryByTestId = exports.queryAllByTestId = exports.getByTestId = exports.getAllByTestId = exports.findByTestId = exports.findAllByTestId = void 0;
7
7
 
8
+ var _matches = require("../matches");
9
+
8
10
  var _makeQueries = require("./makeQueries");
9
11
 
10
- const getNodeByTestId = (node, testID) => {
11
- return typeof testID === 'string' ? testID === node.props.testID : testID.test(node.props.testID);
12
+ const getNodeByTestId = (node, testID, options = {}) => {
13
+ const {
14
+ exact,
15
+ normalizer
16
+ } = options;
17
+ return (0, _matches.matches)(testID, node.props.testID, normalizer, exact);
12
18
  };
13
19
 
14
- const queryAllByTestId = instance => function queryAllByTestIdFn(testId) {
15
- const results = instance.findAll(node => getNodeByTestId(node, testId)).filter(element => typeof element.type === 'string');
20
+ const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
21
+ const results = instance.findAll(node => getNodeByTestId(node, testId, queryOptions)).filter(element => typeof element.type === 'string');
16
22
  return results;
17
23
  };
18
24
 
@@ -1,19 +1,23 @@
1
1
  // @flow
2
+ import { matches } from '../matches';
2
3
  import { makeQueries } from './makeQueries';
3
4
  import type { Queries } from './makeQueries';
5
+ import type { TextMatchOptions } from './byText';
4
6
 
5
- const getNodeByTestId = (node, testID) => {
6
- return typeof testID === 'string'
7
- ? testID === node.props.testID
8
- : testID.test(node.props.testID);
7
+ const getNodeByTestId = (node, testID, options?: TextMatchOptions = {}) => {
8
+ const { exact, normalizer } = options;
9
+ return matches(testID, node.props.testID, normalizer, exact);
9
10
  };
10
11
 
11
12
  const queryAllByTestId = (
12
13
  instance: ReactTestInstance
13
- ): ((testId: string | RegExp) => Array<ReactTestInstance>) =>
14
- function queryAllByTestIdFn(testId) {
14
+ ): ((
15
+ testId: string | RegExp,
16
+ queryOptions?: TextMatchOptions
17
+ ) => Array<ReactTestInstance>) =>
18
+ function queryAllByTestIdFn(testId, queryOptions) {
15
19
  const results = instance
16
- .findAll((node) => getNodeByTestId(node, testId))
20
+ .findAll((node) => getNodeByTestId(node, testId, queryOptions))
17
21
  .filter((element) => typeof element.type === 'string');
18
22
 
19
23
  return results;
@@ -7,6 +7,8 @@ exports.queryByText = exports.queryAllByText = exports.getByText = exports.getAl
7
7
 
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
 
10
+ var _matches = require("../matches");
11
+
10
12
  var _makeQueries = require("./makeQueries");
11
13
 
12
14
  var _filterNodeByType = require("./filterNodeByType");
@@ -17,7 +19,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
17
19
 
18
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
21
 
20
- const getChildrenAsText = (children, TextComponent, textContent = []) => {
22
+ const getChildrenAsText = (children, TextComponent) => {
23
+ const textContent = [];
21
24
  React.Children.forEach(children, child => {
22
25
  var _child$props;
23
26
 
@@ -40,13 +43,13 @@ const getChildrenAsText = (children, TextComponent, textContent = []) => {
40
43
  return;
41
44
  }
42
45
 
43
- getChildrenAsText(child.props.children, TextComponent, textContent);
46
+ getChildrenAsText(child.props.children, TextComponent);
44
47
  }
45
48
  });
46
49
  return textContent;
47
50
  };
48
51
 
49
- const getNodeByText = (node, text) => {
52
+ const getNodeByText = (node, text, options = {}) => {
50
53
  try {
51
54
  const {
52
55
  Text
@@ -59,7 +62,11 @@ const getNodeByText = (node, text) => {
59
62
 
60
63
  if (textChildren) {
61
64
  const textToTest = textChildren.join('');
62
- return typeof text === 'string' ? text === textToTest : text.test(textToTest);
65
+ const {
66
+ exact,
67
+ normalizer
68
+ } = options;
69
+ return (0, _matches.matches)(text, textToTest, normalizer, exact);
63
70
  }
64
71
  }
65
72
 
@@ -69,8 +76,8 @@ const getNodeByText = (node, text) => {
69
76
  }
70
77
  };
71
78
 
72
- const queryAllByText = instance => function queryAllByTextFn(text) {
73
- const results = instance.findAll(node => getNodeByText(node, text));
79
+ const queryAllByText = instance => function queryAllByTextFn(text, queryOptions) {
80
+ const results = instance.findAll(node => getNodeByText(node, text, queryOptions));
74
81
  return results;
75
82
  };
76
83
 
@@ -1,11 +1,19 @@
1
1
  // @flow
2
2
  import * as React from 'react';
3
+ import { matches } from '../matches';
4
+ import type { NormalizerFn } from '../matches';
3
5
  import { makeQueries } from './makeQueries';
4
6
  import type { Queries } from './makeQueries';
5
7
  import { filterNodeByType } from './filterNodeByType';
6
8
  import { createLibraryNotSupportedError } from './errors';
7
9
 
8
- const getChildrenAsText = (children, TextComponent, textContent = []) => {
10
+ export type TextMatchOptions = {
11
+ exact?: boolean,
12
+ normalizer?: NormalizerFn,
13
+ };
14
+
15
+ const getChildrenAsText = (children, TextComponent) => {
16
+ const textContent = [];
9
17
  React.Children.forEach(children, (child) => {
10
18
  if (typeof child === 'string') {
11
19
  textContent.push(child);
@@ -26,14 +34,18 @@ const getChildrenAsText = (children, TextComponent, textContent = []) => {
26
34
  return;
27
35
  }
28
36
 
29
- getChildrenAsText(child.props.children, TextComponent, textContent);
37
+ getChildrenAsText(child.props.children, TextComponent);
30
38
  }
31
39
  });
32
40
 
33
41
  return textContent;
34
42
  };
35
43
 
36
- const getNodeByText = (node, text: string | RegExp) => {
44
+ const getNodeByText = (
45
+ node,
46
+ text: string | RegExp,
47
+ options?: TextMatchOptions = {}
48
+ ) => {
37
49
  try {
38
50
  const { Text } = require('react-native');
39
51
  const isTextComponent = filterNodeByType(node, Text);
@@ -41,9 +53,8 @@ const getNodeByText = (node, text: string | RegExp) => {
41
53
  const textChildren = getChildrenAsText(node.props.children, Text);
42
54
  if (textChildren) {
43
55
  const textToTest = textChildren.join('');
44
- return typeof text === 'string'
45
- ? text === textToTest
46
- : text.test(textToTest);
56
+ const { exact, normalizer } = options;
57
+ return matches(text, textToTest, normalizer, exact);
47
58
  }
48
59
  }
49
60
  return false;
@@ -54,9 +65,14 @@ const getNodeByText = (node, text: string | RegExp) => {
54
65
 
55
66
  const queryAllByText = (
56
67
  instance: ReactTestInstance
57
- ): ((text: string | RegExp) => Array<ReactTestInstance>) =>
58
- function queryAllByTextFn(text) {
59
- const results = instance.findAll((node) => getNodeByText(node, text));
68
+ ): ((
69
+ text: string | RegExp,
70
+ queryOptions?: TextMatchOptions
71
+ ) => Array<ReactTestInstance>) =>
72
+ function queryAllByTextFn(text, queryOptions) {
73
+ const results = instance.findAll((node) =>
74
+ getNodeByText(node, text, queryOptions)
75
+ );
60
76
 
61
77
  return results;
62
78
  };
@@ -64,7 +64,8 @@ const warned = {};
64
64
  function printDeprecationWarning(functionName) {
65
65
  if (warned[functionName]) {
66
66
  return;
67
- }
67
+ } // eslint-disable-next-line no-console
68
+
68
69
 
69
70
  console.warn(`
70
71
  Deprecation Warning:
@@ -53,6 +53,7 @@ export function printDeprecationWarning(functionName: string) {
53
53
  return;
54
54
  }
55
55
 
56
+ // eslint-disable-next-line no-console
56
57
  console.warn(`
57
58
  Deprecation Warning:
58
59
  Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.
@@ -1,5 +1,6 @@
1
1
  // @flow
2
2
  import type { WaitForOptions } from '../waitFor';
3
+ import type { TextMatchOptions } from './byText';
3
4
  import { findAllByTestId, findByTestId } from './byTestId';
4
5
  import { findAllByText, findByText } from './byText';
5
6
  import {
@@ -12,36 +13,44 @@ import { throwRenamedFunctionError } from './errors';
12
13
  export type FindByAPI = {|
13
14
  findAllByDisplayValue: (
14
15
  value: string | RegExp,
16
+ queryOptions?: TextMatchOptions & WaitForOptions,
15
17
  waitForOptions?: WaitForOptions
16
18
  ) => Promise<Array<ReactTestInstance>>,
17
19
  findAllByPlaceholder: () => void,
18
20
  findAllByPlaceholderText: (
19
21
  placeholder: string | RegExp,
22
+ queryOptions?: TextMatchOptions & WaitForOptions,
20
23
  waitForOptions?: WaitForOptions
21
24
  ) => Promise<Array<ReactTestInstance>>,
22
25
  findAllByTestId: (
23
26
  testId: string | RegExp,
27
+ queryOptions?: TextMatchOptions & WaitForOptions,
24
28
  waitForOptions?: WaitForOptions
25
29
  ) => Promise<Array<ReactTestInstance>>,
26
30
  findAllByText: (
27
31
  text: string | RegExp,
32
+ queryOptions?: TextMatchOptions & WaitForOptions,
28
33
  waitForOptions?: WaitForOptions
29
34
  ) => Promise<Array<ReactTestInstance>>,
30
35
  findByDisplayValue: (
31
36
  value: string | RegExp,
37
+ queryOptions?: TextMatchOptions & WaitForOptions,
32
38
  waitForOptions?: WaitForOptions
33
39
  ) => Promise<ReactTestInstance>,
34
40
  findByPlaceholder: () => void,
35
41
  findByPlaceholderText: (
36
42
  placeholder: string | RegExp,
43
+ queryOptions?: TextMatchOptions & WaitForOptions,
37
44
  waitForOptions?: WaitForOptions
38
45
  ) => Promise<ReactTestInstance>,
39
46
  findByTestId: (
40
47
  testId: string | RegExp,
48
+ queryOptions?: TextMatchOptions & WaitForOptions,
41
49
  waitForOptions?: WaitForOptions
42
50
  ) => Promise<ReactTestInstance>,
43
51
  findByText: (
44
52
  text: string | RegExp,
53
+ queryOptions?: TextMatchOptions & WaitForOptions,
45
54
  waitForOptions?: WaitForOptions
46
55
  ) => Promise<ReactTestInstance>,
47
56
  |};
@@ -14,18 +14,41 @@ import {
14
14
  getByPlaceholderText,
15
15
  } from './byPlaceholderText';
16
16
  import { getAllByDisplayValue, getByDisplayValue } from './byDisplayValue';
17
+ import type { TextMatchOptions } from './byText';
17
18
 
18
19
  export type GetByAPI = {|
19
- getByText: (text: string | RegExp) => ReactTestInstance,
20
- getByPlaceholderText: (placeholder: string | RegExp) => ReactTestInstance,
21
- getByDisplayValue: (value: string | RegExp) => ReactTestInstance,
22
- getByTestId: (testID: string | RegExp) => ReactTestInstance,
23
- getAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>,
24
- getAllByText: (text: string | RegExp) => Array<ReactTestInstance>,
20
+ getByText: (
21
+ text: string | RegExp,
22
+ queryOptions?: TextMatchOptions
23
+ ) => ReactTestInstance,
24
+ getByPlaceholderText: (
25
+ placeholder: string | RegExp,
26
+ queryOptions?: TextMatchOptions
27
+ ) => ReactTestInstance,
28
+ getByDisplayValue: (
29
+ value: string | RegExp,
30
+ queryOptions?: TextMatchOptions
31
+ ) => ReactTestInstance,
32
+ getByTestId: (
33
+ testID: string | RegExp,
34
+ queryOptions?: TextMatchOptions
35
+ ) => ReactTestInstance,
36
+ getAllByTestId: (
37
+ testID: string | RegExp,
38
+ queryOptions?: TextMatchOptions
39
+ ) => Array<ReactTestInstance>,
40
+ getAllByText: (
41
+ text: string | RegExp,
42
+ queryOptions?: TextMatchOptions
43
+ ) => Array<ReactTestInstance>,
25
44
  getAllByPlaceholderText: (
26
- placeholder: string | RegExp
45
+ placeholder: string | RegExp,
46
+ queryOptions?: TextMatchOptions
47
+ ) => Array<ReactTestInstance>,
48
+ getAllByDisplayValue: (
49
+ value: string | RegExp,
50
+ queryOptions?: TextMatchOptions
27
51
  ) => Array<ReactTestInstance>,
28
- getAllByDisplayValue: (value: string | RegExp) => Array<ReactTestInstance>,
29
52
 
30
53
  // Unsafe aliases
31
54
  UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance,
@@ -11,10 +11,34 @@ var _errors = require("./errors");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
+ // The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
15
+ // To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
16
+ const deprecatedKeys = ['timeout', 'interval', 'stackTraceError'];
17
+
18
+ const extractDeprecatedWaitForOptionUsage = queryOptions => {
19
+ if (queryOptions) {
20
+ const waitForOptions = {
21
+ timeout: queryOptions.timeout,
22
+ interval: queryOptions.interval,
23
+ stackTraceError: queryOptions.stackTraceError
24
+ };
25
+ deprecatedKeys.forEach(key => {
26
+ if (queryOptions[key]) {
27
+ // eslint-disable-next-line no-console
28
+ console.warn(`Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
29
+ Example:
30
+
31
+ findByText(text, {}, { ${key}: ${queryOptions[key].toString()} })`);
32
+ }
33
+ });
34
+ return waitForOptions;
35
+ }
36
+ };
37
+
14
38
  function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
15
39
  function getAllByQuery(instance) {
16
- return function getAllFn(args) {
17
- const results = queryAllByQuery(instance)(args);
40
+ return function getAllFn(args, queryOptions) {
41
+ const results = queryAllByQuery(instance)(args, queryOptions);
18
42
 
19
43
  if (results.length === 0) {
20
44
  throw new _errors.ErrorWithStack(getMissingError(args), getAllFn);
@@ -25,8 +49,8 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
25
49
  }
26
50
 
27
51
  function queryByQuery(instance) {
28
- return function singleQueryFn(args) {
29
- const results = queryAllByQuery(instance)(args);
52
+ return function singleQueryFn(args, queryOptions) {
53
+ const results = queryAllByQuery(instance)(args, queryOptions);
30
54
 
31
55
  if (results.length > 1) {
32
56
  throw new _errors.ErrorWithStack(getMultipleError(args), singleQueryFn);
@@ -41,8 +65,8 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
41
65
  }
42
66
 
43
67
  function getByQuery(instance) {
44
- return function getFn(args) {
45
- const results = queryAllByQuery(instance)(args);
68
+ return function getFn(args, queryOptions) {
69
+ const results = queryAllByQuery(instance)(args, queryOptions);
46
70
 
47
71
  if (results.length > 1) {
48
72
  throw new _errors.ErrorWithStack(getMultipleError(args), getFn);
@@ -57,14 +81,20 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
57
81
  }
58
82
 
59
83
  function findAllByQuery(instance) {
60
- return function findAllFn(args, waitForOptions = {}) {
61
- return (0, _waitFor.default)(() => getAllByQuery(instance)(args), waitForOptions);
84
+ return function findAllFn(args, queryOptions, waitForOptions = {}) {
85
+ const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(queryOptions);
86
+ return (0, _waitFor.default)(() => getAllByQuery(instance)(args, queryOptions), { ...deprecatedWaitForOptions,
87
+ ...waitForOptions
88
+ });
62
89
  };
63
90
  }
64
91
 
65
92
  function findByQuery(instance) {
66
- return function findFn(args, waitForOptions = {}) {
67
- return (0, _waitFor.default)(() => getByQuery(instance)(args), waitForOptions);
93
+ return function findFn(args, queryOptions, waitForOptions = {}) {
94
+ const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(queryOptions);
95
+ return (0, _waitFor.default)(() => getByQuery(instance)(args, queryOptions), { ...deprecatedWaitForOptions,
96
+ ...waitForOptions
97
+ });
68
98
  };
69
99
  }
70
100
 
@@ -2,14 +2,19 @@
2
2
  import waitFor from '../waitFor';
3
3
  import type { WaitForOptions } from '../waitFor';
4
4
  import { ErrorWithStack } from './errors';
5
+ import type { TextMatchOptions } from './byText';
5
6
 
6
7
  type QueryFunction<ArgType, ReturnType> = (
7
8
  instance: ReactTestInstance
8
- ) => (args: ArgType) => ReturnType;
9
+ ) => (args: ArgType, queryOptions?: TextMatchOptions) => ReturnType;
9
10
 
10
11
  type FindQueryFunction<ArgType, ReturnType> = (
11
12
  instance: ReactTestInstance
12
- ) => (args: ArgType, waitForOptions?: WaitForOptions) => Promise<ReturnType>;
13
+ ) => (
14
+ args: ArgType,
15
+ queryOptions?: TextMatchOptions & WaitForOptions,
16
+ waitForOptions?: WaitForOptions
17
+ ) => Promise<ReturnType>;
13
18
 
14
19
  type QueryAllByQuery<QueryArg> = QueryFunction<
15
20
  QueryArg,
@@ -37,14 +42,43 @@ export type Queries<QueryArg> = {
37
42
  findAllBy: FindAllByQuery<QueryArg>,
38
43
  };
39
44
 
45
+ // The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
46
+ // To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
47
+ const deprecatedKeys: $Keys<WaitForOptions>[] = [
48
+ 'timeout',
49
+ 'interval',
50
+ 'stackTraceError',
51
+ ];
52
+ const extractDeprecatedWaitForOptionUsage = (queryOptions?: WaitForOptions) => {
53
+ if (queryOptions) {
54
+ const waitForOptions: WaitForOptions = {
55
+ timeout: queryOptions.timeout,
56
+ interval: queryOptions.interval,
57
+ stackTraceError: queryOptions.stackTraceError,
58
+ };
59
+ deprecatedKeys.forEach((key) => {
60
+ if (queryOptions[key]) {
61
+ // eslint-disable-next-line no-console
62
+ console.warn(
63
+ `Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
64
+ Example:
65
+
66
+ findByText(text, {}, { ${key}: ${queryOptions[key].toString()} })`
67
+ );
68
+ }
69
+ });
70
+ return waitForOptions;
71
+ }
72
+ };
73
+
40
74
  export function makeQueries<QueryArg>(
41
75
  queryAllByQuery: QueryAllByQuery<QueryArg>,
42
76
  getMissingError: (args: QueryArg) => string,
43
77
  getMultipleError: (args: QueryArg) => string
44
78
  ): Queries<QueryArg> {
45
79
  function getAllByQuery(instance: ReactTestInstance) {
46
- return function getAllFn(args: QueryArg) {
47
- const results = queryAllByQuery(instance)(args);
80
+ return function getAllFn(args: QueryArg, queryOptions?: TextMatchOptions) {
81
+ const results = queryAllByQuery(instance)(args, queryOptions);
48
82
 
49
83
  if (results.length === 0) {
50
84
  throw new ErrorWithStack(getMissingError(args), getAllFn);
@@ -55,8 +89,11 @@ export function makeQueries<QueryArg>(
55
89
  }
56
90
 
57
91
  function queryByQuery(instance: ReactTestInstance) {
58
- return function singleQueryFn(args: QueryArg) {
59
- const results = queryAllByQuery(instance)(args);
92
+ return function singleQueryFn(
93
+ args: QueryArg,
94
+ queryOptions?: TextMatchOptions
95
+ ) {
96
+ const results = queryAllByQuery(instance)(args, queryOptions);
60
97
 
61
98
  if (results.length > 1) {
62
99
  throw new ErrorWithStack(getMultipleError(args), singleQueryFn);
@@ -71,8 +108,8 @@ export function makeQueries<QueryArg>(
71
108
  }
72
109
 
73
110
  function getByQuery(instance: ReactTestInstance) {
74
- return function getFn(args: QueryArg) {
75
- const results = queryAllByQuery(instance)(args);
111
+ return function getFn(args: QueryArg, queryOptions?: TextMatchOptions) {
112
+ const results = queryAllByQuery(instance)(args, queryOptions);
76
113
 
77
114
  if (results.length > 1) {
78
115
  throw new ErrorWithStack(getMultipleError(args), getFn);
@@ -89,18 +126,32 @@ export function makeQueries<QueryArg>(
89
126
  function findAllByQuery(instance: ReactTestInstance) {
90
127
  return function findAllFn(
91
128
  args: QueryArg,
129
+ queryOptions?: TextMatchOptions & WaitForOptions,
92
130
  waitForOptions?: WaitForOptions = {}
93
131
  ) {
94
- return waitFor(() => getAllByQuery(instance)(args), waitForOptions);
132
+ const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
133
+ queryOptions
134
+ );
135
+ return waitFor(() => getAllByQuery(instance)(args, queryOptions), {
136
+ ...deprecatedWaitForOptions,
137
+ ...waitForOptions,
138
+ });
95
139
  };
96
140
  }
97
141
 
98
142
  function findByQuery(instance: ReactTestInstance) {
99
143
  return function findFn(
100
144
  args: QueryArg,
145
+ queryOptions?: TextMatchOptions & WaitForOptions,
101
146
  waitForOptions?: WaitForOptions = {}
102
147
  ) {
103
- return waitFor(() => getByQuery(instance)(args), waitForOptions);
148
+ const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
149
+ queryOptions
150
+ );
151
+ return waitFor(() => getByQuery(instance)(args, queryOptions), {
152
+ ...deprecatedWaitForOptions,
153
+ ...waitForOptions,
154
+ });
104
155
  };
105
156
  }
106
157
 
@@ -1,5 +1,6 @@
1
1
  // @flow
2
2
  import * as React from 'react';
3
+ import type { TextMatchOptions } from './byText';
3
4
  import {
4
5
  UNSAFE_getByType,
5
6
  UNSAFE_getByProps,
@@ -20,18 +21,32 @@ import {
20
21
  } from './errors';
21
22
 
22
23
  export type QueryByAPI = {|
23
- queryByText: (name: string | RegExp) => ReactTestInstance | null,
24
+ queryByText: (
25
+ name: string | RegExp,
26
+ queryOptions?: TextMatchOptions
27
+ ) => ReactTestInstance | null,
28
+ queryAllByText: (
29
+ text: string | RegExp,
30
+ queryOptions?: TextMatchOptions
31
+ ) => Array<ReactTestInstance>,
24
32
  queryByPlaceholderText: (
25
- placeholder: string | RegExp
33
+ placeholder: string | RegExp,
34
+ queryOptions?: TextMatchOptions
26
35
  ) => ReactTestInstance | null,
27
- queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null,
28
- queryByTestId: (testID: string | RegExp) => ReactTestInstance | null,
29
- queryAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>,
30
- queryAllByText: (text: string | RegExp) => Array<ReactTestInstance>,
31
36
  queryAllByPlaceholderText: (
32
- placeholder: string | RegExp
37
+ placeholder: string | RegExp,
38
+ queryOptions?: TextMatchOptions
33
39
  ) => Array<ReactTestInstance>,
34
- queryAllByDisplayValue: (value: string | RegExp) => Array<ReactTestInstance>,
40
+ queryByDisplayValue: (
41
+ value: string | RegExp,
42
+ queryOptions?: TextMatchOptions
43
+ ) => ReactTestInstance | null,
44
+ queryAllByDisplayValue: (
45
+ value: string | RegExp,
46
+ queryOptions?: TextMatchOptions
47
+ ) => Array<ReactTestInstance>,
48
+ queryByTestId: (testID: string | RegExp) => ReactTestInstance | null,
49
+ queryAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>,
35
50
 
36
51
  // Unsafe aliases
37
52
  UNSAFE_queryByType: <P>(
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.matches = matches;
7
+ exports.getDefaultNormalizer = getDefaultNormalizer;
8
+
9
+ function matches(matcher, text, normalizer = getDefaultNormalizer(), exact = true) {
10
+ if (typeof text !== 'string') {
11
+ return false;
12
+ }
13
+
14
+ const normalizedText = normalizer(text);
15
+
16
+ if (typeof matcher === 'string') {
17
+ return exact ? normalizedText === matcher : normalizedText.toLowerCase().includes(matcher.toLowerCase());
18
+ } else {
19
+ return matcher.test(normalizedText);
20
+ }
21
+ }
22
+
23
+ function getDefaultNormalizer({
24
+ trim = true,
25
+ collapseWhitespace = true
26
+ } = {}) {
27
+ return text => {
28
+ let normalizedText = text;
29
+ normalizedText = trim ? normalizedText.trim() : normalizedText;
30
+ normalizedText = collapseWhitespace ? normalizedText.replace(/\s+/g, ' ') : normalizedText;
31
+ return normalizedText;
32
+ };
33
+ }
@@ -0,0 +1,41 @@
1
+ // @flow
2
+ export type NormalizerFn = (textToNormalize: string) => string;
3
+
4
+ export function matches(
5
+ matcher: string | RegExp,
6
+ text: string,
7
+ normalizer?: NormalizerFn = getDefaultNormalizer(),
8
+ exact?: boolean = true
9
+ ): boolean {
10
+ if (typeof text !== 'string') {
11
+ return false;
12
+ }
13
+
14
+ const normalizedText = normalizer(text);
15
+ if (typeof matcher === 'string') {
16
+ return exact
17
+ ? normalizedText === matcher
18
+ : normalizedText.toLowerCase().includes(matcher.toLowerCase());
19
+ } else {
20
+ return matcher.test(normalizedText);
21
+ }
22
+ }
23
+
24
+ type NormalizerConfig = {
25
+ trim?: boolean,
26
+ collapseWhitespace?: boolean,
27
+ };
28
+
29
+ export function getDefaultNormalizer({
30
+ trim = true,
31
+ collapseWhitespace = true,
32
+ }: NormalizerConfig = {}): NormalizerFn {
33
+ return (text: string) => {
34
+ let normalizedText = text;
35
+ normalizedText = trim ? normalizedText.trim() : normalizedText;
36
+ normalizedText = collapseWhitespace
37
+ ? normalizedText.replace(/\s+/g, ' ')
38
+ : normalizedText;
39
+ return normalizedText;
40
+ };
41
+ }
package/build/pure.js CHANGED
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "getQueriesForElement", {
69
69
  return _within.getQueriesForElement;
70
70
  }
71
71
  });
72
+ Object.defineProperty(exports, "getDefaultNormalizer", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _matches.getDefaultNormalizer;
76
+ }
77
+ });
72
78
 
73
79
  var _act = _interopRequireDefault(require("./act"));
74
80
 
@@ -88,6 +94,8 @@ var _waitForElementToBeRemoved = _interopRequireDefault(require("./waitForElemen
88
94
 
89
95
  var _within = require("./within");
90
96
 
97
+ var _matches = require("./matches");
98
+
91
99
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
92
100
 
93
101
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -8,6 +8,7 @@ import shallow from './shallow';
8
8
  import waitFor, { waitForElement } from './waitFor';
9
9
  import waitForElementToBeRemoved from './waitForElementToBeRemoved';
10
10
  import { within, getQueriesForElement } from './within';
11
+ import { getDefaultNormalizer } from './matches';
11
12
 
12
13
  export { act };
13
14
  export { cleanup };
@@ -18,3 +19,4 @@ export { shallow };
18
19
  export { waitFor, waitForElement };
19
20
  export { waitForElementToBeRemoved };
20
21
  export { within, getQueriesForElement };
22
+ export { getDefaultNormalizer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/react-native",
3
- "version": "8.0.0",
3
+ "version": "9.0.0-alpha.0",
4
4
  "description": "Simple and complete React Native testing utilities that encourage good testing practices.",
5
5
  "main": "build/index.js",
6
6
  "typings": "./typings/index.d.ts",
@@ -14,17 +14,38 @@ type QueryAllReturn = Array<ReactTestInstance> | [];
14
14
  type FindReturn = Promise<ReactTestInstance>;
15
15
  type FindAllReturn = Promise<ReactTestInstance[]>;
16
16
 
17
+ type TextMatch = string | RegExp;
18
+
17
19
  interface GetByAPI {
18
- getByText: (text: string | RegExp) => ReactTestInstance;
19
- getByPlaceholderText: (placeholder: string | RegExp) => ReactTestInstance;
20
- getByDisplayValue: (value: string | RegExp) => ReactTestInstance;
21
- getByTestId: (testID: string | RegExp) => ReactTestInstance;
22
- getAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>;
23
- getAllByText: (text: string | RegExp) => Array<ReactTestInstance>;
20
+ getByText: (text: TextMatch, options?: TextMatchOptions) => ReactTestInstance;
21
+ getByPlaceholderText: (
22
+ placeholder: TextMatch,
23
+ options?: TextMatchOptions
24
+ ) => ReactTestInstance;
25
+ getByDisplayValue: (
26
+ value: TextMatch,
27
+ options?: TextMatchOptions
28
+ ) => ReactTestInstance;
29
+ getByTestId: (
30
+ testID: TextMatch,
31
+ options?: TextMatchOptions
32
+ ) => ReactTestInstance;
33
+ getAllByTestId: (
34
+ testID: TextMatch,
35
+ options?: TextMatchOptions
36
+ ) => Array<ReactTestInstance>;
37
+ getAllByText: (
38
+ text: TextMatch,
39
+ options?: TextMatchOptions
40
+ ) => Array<ReactTestInstance>;
24
41
  getAllByPlaceholderText: (
25
- placeholder: string | RegExp
42
+ placeholder: TextMatch,
43
+ options?: TextMatchOptions
44
+ ) => Array<ReactTestInstance>;
45
+ getAllByDisplayValue: (
46
+ value: TextMatch,
47
+ options?: TextMatchOptions
26
48
  ) => Array<ReactTestInstance>;
27
- getAllByDisplayValue: (value: string | RegExp) => Array<ReactTestInstance>;
28
49
 
29
50
  // Unsafe aliases
30
51
  UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
@@ -64,19 +85,31 @@ interface GetByAPI {
64
85
  }
65
86
 
66
87
  interface QueryByAPI {
67
- queryByText: (name: string | RegExp) => ReactTestInstance | null;
88
+ queryByText: (
89
+ name: TextMatch,
90
+ options?: TextMatchOptions
91
+ ) => ReactTestInstance | null;
68
92
  queryByPlaceholderText: (
69
- placeholder: string | RegExp
93
+ placeholder: TextMatch,
94
+ options?: TextMatchOptions
95
+ ) => ReactTestInstance | null;
96
+ queryByDisplayValue: (
97
+ value: TextMatch,
98
+ options?: TextMatchOptions
70
99
  ) => ReactTestInstance | null;
71
- queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null;
72
- queryByTestId: (testID: string | RegExp) => ReactTestInstance | null;
73
- queryAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance> | [];
74
- queryAllByText: (text: string | RegExp) => Array<ReactTestInstance> | [];
100
+ queryByTestId: (testID: TextMatch) => ReactTestInstance | null;
101
+ queryAllByTestId: (testID: TextMatch) => Array<ReactTestInstance> | [];
102
+ queryAllByText: (
103
+ text: TextMatch,
104
+ options?: TextMatchOptions
105
+ ) => Array<ReactTestInstance> | [];
75
106
  queryAllByPlaceholderText: (
76
- placeholder: string | RegExp
107
+ placeholder: TextMatch,
108
+ options?: TextMatchOptions
77
109
  ) => Array<ReactTestInstance> | [];
78
110
  queryAllByDisplayValue: (
79
- value: string | RegExp
111
+ value: TextMatch,
112
+ options?: TextMatchOptions
80
113
  ) => Array<ReactTestInstance> | [];
81
114
 
82
115
  // Unsafe aliases
@@ -126,35 +159,43 @@ interface QueryByAPI {
126
159
 
127
160
  interface FindByAPI {
128
161
  findByText: (
129
- text: string | RegExp,
162
+ text: TextMatch,
163
+ queryOptions?: TextMatchOptions,
130
164
  waitForOptions?: WaitForOptions
131
165
  ) => FindReturn;
132
166
  findByPlaceholderText: (
133
- placeholder: string | RegExp,
167
+ placeholder: TextMatch,
168
+ queryOptions?: TextMatchOptions,
134
169
  waitForOptions?: WaitForOptions
135
170
  ) => FindReturn;
136
171
  findByDisplayValue: (
137
- value: string | RegExp,
172
+ value: TextMatch,
173
+ queryOptions?: TextMatchOptions,
138
174
  waitForOptions?: WaitForOptions
139
175
  ) => FindReturn;
140
176
  findByTestId: (
141
- testID: string | RegExp,
177
+ testID: TextMatch,
178
+ queryOptions?: TextMatchOptions,
142
179
  waitForOptions?: WaitForOptions
143
180
  ) => FindReturn;
144
181
  findAllByText: (
145
- text: string | RegExp,
182
+ text: TextMatch,
183
+ queryOptions?: TextMatchOptions,
146
184
  waitForOptions?: WaitForOptions
147
185
  ) => FindAllReturn;
148
186
  findAllByPlaceholderText: (
149
- placeholder: string | RegExp,
187
+ placeholder: TextMatch,
188
+ queryOptions?: TextMatchOptions,
150
189
  waitForOptions?: WaitForOptions
151
190
  ) => FindAllReturn;
152
191
  findAllByDisplayValue: (
153
- value: string | RegExp,
192
+ value: TextMatch,
193
+ queryOptions?: TextMatchOptions,
154
194
  waitForOptions?: WaitForOptions
155
195
  ) => FindAllReturn;
156
196
  findAllByTestId: (
157
- testID: string | RegExp,
197
+ testID: TextMatch,
198
+ queryOptions?: TextMatchOptions,
158
199
  waitForOptions?: WaitForOptions
159
200
  ) => FindAllReturn;
160
201
  }
@@ -169,54 +210,54 @@ export type A11yValue = {
169
210
 
170
211
  type A11yAPI = {
171
212
  // Label
172
- getByA11yLabel: (matcher: string | RegExp) => GetReturn;
173
- getByLabelText: (matcher: string | RegExp) => GetReturn;
174
- getAllByA11yLabel: (matcher: string | RegExp) => GetAllReturn;
175
- getAllByLabelText: (matcher: string | RegExp) => GetAllReturn;
176
- queryByA11yLabel: (matcher: string | RegExp) => QueryReturn;
177
- queryByLabelText: (matcher: string | RegExp) => QueryReturn;
178
- queryAllByA11yLabel: (matcher: string | RegExp) => QueryAllReturn;
179
- queryAllByLabelText: (matcher: string | RegExp) => QueryAllReturn;
213
+ getByA11yLabel: (matcher: TextMatch) => GetReturn;
214
+ getByLabelText: (matcher: TextMatch) => GetReturn;
215
+ getAllByA11yLabel: (matcher: TextMatch) => GetAllReturn;
216
+ getAllByLabelText: (matcher: TextMatch) => GetAllReturn;
217
+ queryByA11yLabel: (matcher: TextMatch) => QueryReturn;
218
+ queryByLabelText: (matcher: TextMatch) => QueryReturn;
219
+ queryAllByA11yLabel: (matcher: TextMatch) => QueryAllReturn;
220
+ queryAllByLabelText: (matcher: TextMatch) => QueryAllReturn;
180
221
  findByA11yLabel: (
181
- matcher: string | RegExp,
222
+ matcher: TextMatch,
182
223
  waitForOptions?: WaitForOptions
183
224
  ) => FindReturn;
184
225
  findByLabelText: (
185
- matcher: string | RegExp,
226
+ matcher: TextMatch,
186
227
  waitForOptions?: WaitForOptions
187
228
  ) => FindReturn;
188
229
  findAllByA11yLabel: (
189
- matcher: string | RegExp,
230
+ matcher: TextMatch,
190
231
  waitForOptions?: WaitForOptions
191
232
  ) => FindAllReturn;
192
233
  findAllByLabelText: (
193
- matcher: string | RegExp,
234
+ matcher: TextMatch,
194
235
  waitForOptions?: WaitForOptions
195
236
  ) => FindAllReturn;
196
237
 
197
238
  // Hint
198
- getByA11yHint: (matcher: string | RegExp) => GetReturn;
199
- getByHintText: (matcher: string | RegExp) => GetReturn;
200
- getAllByA11yHint: (matcher: string | RegExp) => GetAllReturn;
201
- getAllByHintText: (matcher: string | RegExp) => GetAllReturn;
202
- queryByA11yHint: (matcher: string | RegExp) => QueryReturn;
203
- queryByHintText: (matcher: string | RegExp) => QueryReturn;
204
- queryAllByA11yHint: (matcher: string | RegExp) => QueryAllReturn;
205
- queryAllByHintText: (matcher: string | RegExp) => QueryAllReturn;
239
+ getByA11yHint: (matcher: TextMatch) => GetReturn;
240
+ getByHintText: (matcher: TextMatch) => GetReturn;
241
+ getAllByA11yHint: (matcher: TextMatch) => GetAllReturn;
242
+ getAllByHintText: (matcher: TextMatch) => GetAllReturn;
243
+ queryByA11yHint: (matcher: TextMatch) => QueryReturn;
244
+ queryByHintText: (matcher: TextMatch) => QueryReturn;
245
+ queryAllByA11yHint: (matcher: TextMatch) => QueryAllReturn;
246
+ queryAllByHintText: (matcher: TextMatch) => QueryAllReturn;
206
247
  findByA11yHint: (
207
- matcher: string | RegExp,
248
+ matcher: TextMatch,
208
249
  waitForOptions?: WaitForOptions
209
250
  ) => FindReturn;
210
251
  findByHintText: (
211
- matcher: string | RegExp,
252
+ matcher: TextMatch,
212
253
  waitForOptions?: WaitForOptions
213
254
  ) => FindReturn;
214
255
  findAllByA11yHint: (
215
- matcher: string | RegExp,
256
+ matcher: TextMatch,
216
257
  waitForOptions?: WaitForOptions
217
258
  ) => FindAllReturn;
218
259
  findAllByHintText: (
219
- matcher: string | RegExp,
260
+ matcher: TextMatch,
220
261
  waitForOptions?: WaitForOptions
221
262
  ) => FindAllReturn;
222
263
 
@@ -334,6 +375,16 @@ export declare const render: (
334
375
  export declare const cleanup: () => void;
335
376
  export declare const fireEvent: FireEventAPI;
336
377
 
378
+ type NormalizerFn = (textToNormalize: string) => string;
379
+ type NormalizerConfig = {
380
+ trim?: boolean;
381
+ collapseWhitespace?: boolean;
382
+ };
383
+ type TextMatchOptions = {
384
+ exact?: boolean;
385
+ normalizer?: NormalizerFn;
386
+ };
387
+
337
388
  type WaitForOptions = {
338
389
  timeout?: number;
339
390
  interval?: number;
@@ -359,6 +410,10 @@ export declare const getQueriesForElement: (
359
410
  instance: ReactTestInstance
360
411
  ) => Queries;
361
412
 
413
+ export declare const getDefaultNormalizer: (
414
+ normalizerConfig?: NormalizerConfig
415
+ ) => NormalizerFn;
416
+
362
417
  /**
363
418
  * @deprecated This function has been removed. Please use `waitFor` function.
364
419
  */