@testing-library/react-native 7.2.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.
- package/README.md +23 -3
- package/build/fireEvent.js +5 -13
- package/build/fireEvent.js.flow +5 -22
- package/build/flushMicroTasks.js +3 -1
- package/build/flushMicroTasks.js.flow +1 -0
- package/build/helpers/byDisplayValue.js +10 -4
- package/build/helpers/byDisplayValue.js.flow +15 -5
- package/build/helpers/byPlaceholderText.js +10 -4
- package/build/helpers/byPlaceholderText.js.flow +15 -7
- package/build/helpers/byTestId.js +10 -4
- package/build/helpers/byTestId.js.flow +11 -7
- package/build/helpers/byText.js +13 -6
- package/build/helpers/byText.js.flow +25 -9
- package/build/helpers/errors.js +2 -1
- package/build/helpers/errors.js.flow +1 -0
- package/build/helpers/findByAPI.js.flow +9 -0
- package/build/helpers/getByAPI.js.flow +31 -8
- package/build/helpers/makeQueries.js +40 -10
- package/build/helpers/makeQueries.js.flow +61 -10
- package/build/helpers/queryByAPI.js.flow +23 -8
- package/build/helpers/timers.js +77 -0
- package/build/helpers/timers.js.flow +88 -0
- package/build/matches.js +33 -0
- package/build/matches.js.flow +41 -0
- package/build/pure.js +8 -0
- package/build/pure.js.flow +2 -0
- package/build/render.js +9 -2
- package/build/render.js.flow +7 -2
- package/build/waitFor.js +147 -21
- package/build/waitFor.js.flow +154 -20
- package/jest-preset/index.js +10 -0
- package/jest-preset/restore-promise.js +1 -0
- package/jest-preset/save-promise.js +1 -0
- package/package.json +16 -11
- package/typings/index.d.ts +106 -51
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
) => (
|
|
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(
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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: (
|
|
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
|
-
|
|
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,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runWithRealTimers = runWithRealTimers;
|
|
7
|
+
exports.setTimeout = exports.setImmediate = exports.clearTimeout = exports.jestFakeTimersAreEnabled = void 0;
|
|
8
|
+
// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
|
|
9
|
+
|
|
10
|
+
/* globals jest */
|
|
11
|
+
const globalObj = typeof window === 'undefined' ? global : window; // Currently this fn only supports jest timers, but it could support other test runners in the future.
|
|
12
|
+
|
|
13
|
+
function runWithRealTimers(callback) {
|
|
14
|
+
const fakeTimersType = getJestFakeTimersType();
|
|
15
|
+
|
|
16
|
+
if (fakeTimersType) {
|
|
17
|
+
jest.useRealTimers();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const callbackReturnValue = callback();
|
|
21
|
+
|
|
22
|
+
if (fakeTimersType) {
|
|
23
|
+
jest.useFakeTimers(fakeTimersType);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return callbackReturnValue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getJestFakeTimersType() {
|
|
30
|
+
// istanbul ignore if
|
|
31
|
+
if (typeof jest === 'undefined' || typeof globalObj.setTimeout === 'undefined') {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof globalObj.setTimeout._isMockFunction !== 'undefined' && globalObj.setTimeout._isMockFunction) {
|
|
36
|
+
return 'legacy';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof globalObj.setTimeout.clock !== 'undefined' && // $FlowIgnore[prop-missing]
|
|
40
|
+
typeof jest.getRealSystemTime !== 'undefined') {
|
|
41
|
+
try {
|
|
42
|
+
// jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
|
|
43
|
+
// $FlowExpectedError
|
|
44
|
+
jest.getRealSystemTime();
|
|
45
|
+
return 'modern';
|
|
46
|
+
} catch {// not using Jest's modern fake timers
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const jestFakeTimersAreEnabled = () => Boolean(getJestFakeTimersType()); // we only run our tests in node, and setImmediate is supported in node.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
exports.jestFakeTimersAreEnabled = jestFakeTimersAreEnabled;
|
|
57
|
+
|
|
58
|
+
function setImmediatePolyfill(fn) {
|
|
59
|
+
return globalObj.setTimeout(fn, 0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function bindTimeFunctions() {
|
|
63
|
+
return {
|
|
64
|
+
clearTimeoutFn: globalObj.clearTimeout,
|
|
65
|
+
setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,
|
|
66
|
+
setTimeoutFn: globalObj.setTimeout
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
clearTimeoutFn,
|
|
72
|
+
setImmediateFn,
|
|
73
|
+
setTimeoutFn
|
|
74
|
+
} = runWithRealTimers(bindTimeFunctions);
|
|
75
|
+
exports.setTimeout = setTimeoutFn;
|
|
76
|
+
exports.setImmediate = setImmediateFn;
|
|
77
|
+
exports.clearTimeout = clearTimeoutFn;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
|
|
2
|
+
// @flow
|
|
3
|
+
/* globals jest */
|
|
4
|
+
|
|
5
|
+
const globalObj = typeof window === 'undefined' ? global : window;
|
|
6
|
+
|
|
7
|
+
// Currently this fn only supports jest timers, but it could support other test runners in the future.
|
|
8
|
+
function runWithRealTimers<T>(callback: () => T): T {
|
|
9
|
+
const fakeTimersType = getJestFakeTimersType();
|
|
10
|
+
if (fakeTimersType) {
|
|
11
|
+
jest.useRealTimers();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const callbackReturnValue = callback();
|
|
15
|
+
|
|
16
|
+
if (fakeTimersType) {
|
|
17
|
+
jest.useFakeTimers(fakeTimersType);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return callbackReturnValue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getJestFakeTimersType() {
|
|
24
|
+
// istanbul ignore if
|
|
25
|
+
if (
|
|
26
|
+
typeof jest === 'undefined' ||
|
|
27
|
+
typeof globalObj.setTimeout === 'undefined'
|
|
28
|
+
) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&
|
|
34
|
+
globalObj.setTimeout._isMockFunction
|
|
35
|
+
) {
|
|
36
|
+
return 'legacy';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
typeof globalObj.setTimeout.clock !== 'undefined' &&
|
|
41
|
+
// $FlowIgnore[prop-missing]
|
|
42
|
+
typeof jest.getRealSystemTime !== 'undefined'
|
|
43
|
+
) {
|
|
44
|
+
try {
|
|
45
|
+
// jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
|
|
46
|
+
// $FlowExpectedError
|
|
47
|
+
jest.getRealSystemTime();
|
|
48
|
+
return 'modern';
|
|
49
|
+
} catch {
|
|
50
|
+
// not using Jest's modern fake timers
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const jestFakeTimersAreEnabled = (): boolean =>
|
|
57
|
+
Boolean(getJestFakeTimersType());
|
|
58
|
+
|
|
59
|
+
// we only run our tests in node, and setImmediate is supported in node.
|
|
60
|
+
function setImmediatePolyfill(fn) {
|
|
61
|
+
return globalObj.setTimeout(fn, 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type BindTimeFunctions = {
|
|
65
|
+
clearTimeoutFn: typeof clearTimeout,
|
|
66
|
+
setImmediateFn: typeof setImmediate,
|
|
67
|
+
setTimeoutFn: typeof setTimeout,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function bindTimeFunctions(): BindTimeFunctions {
|
|
71
|
+
return {
|
|
72
|
+
clearTimeoutFn: globalObj.clearTimeout,
|
|
73
|
+
setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,
|
|
74
|
+
setTimeoutFn: globalObj.setTimeout,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { clearTimeoutFn, setImmediateFn, setTimeoutFn } = (runWithRealTimers(
|
|
79
|
+
bindTimeFunctions
|
|
80
|
+
): BindTimeFunctions);
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
runWithRealTimers,
|
|
84
|
+
jestFakeTimersAreEnabled,
|
|
85
|
+
clearTimeoutFn as clearTimeout,
|
|
86
|
+
setImmediateFn as setImmediate,
|
|
87
|
+
setTimeoutFn as setTimeout,
|
|
88
|
+
};
|
package/build/matches.js
ADDED
|
@@ -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; }
|
package/build/pure.js.flow
CHANGED
|
@@ -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/build/render.js
CHANGED
|
@@ -48,16 +48,23 @@ function render(component, {
|
|
|
48
48
|
} : undefined);
|
|
49
49
|
const update = updateWithAct(renderer, wrap);
|
|
50
50
|
const instance = renderer.root;
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
const unmount = () => {
|
|
53
|
+
(0, _act.default)(() => {
|
|
54
|
+
renderer.unmount();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
(0, _cleanup.addToCleanupQueue)(unmount);
|
|
52
59
|
return { ...(0, _getByAPI.getByAPI)(instance),
|
|
53
60
|
...(0, _queryByAPI.queryByAPI)(instance),
|
|
54
61
|
...(0, _findByAPI.findByAPI)(instance),
|
|
55
62
|
...(0, _a11yAPI.a11yAPI)(instance),
|
|
56
63
|
update,
|
|
64
|
+
unmount,
|
|
57
65
|
container: instance,
|
|
58
66
|
rerender: update,
|
|
59
67
|
// alias for `update`
|
|
60
|
-
unmount: renderer.unmount,
|
|
61
68
|
toJSON: renderer.toJSON,
|
|
62
69
|
debug: debug(instance, renderer)
|
|
63
70
|
};
|
package/build/render.js.flow
CHANGED
|
@@ -46,8 +46,13 @@ export default function render<T>(
|
|
|
46
46
|
);
|
|
47
47
|
const update = updateWithAct(renderer, wrap);
|
|
48
48
|
const instance = renderer.root;
|
|
49
|
+
const unmount = () => {
|
|
50
|
+
act(() => {
|
|
51
|
+
renderer.unmount();
|
|
52
|
+
});
|
|
53
|
+
};
|
|
49
54
|
|
|
50
|
-
addToCleanupQueue(
|
|
55
|
+
addToCleanupQueue(unmount);
|
|
51
56
|
|
|
52
57
|
return {
|
|
53
58
|
...getByAPI(instance),
|
|
@@ -55,9 +60,9 @@ export default function render<T>(
|
|
|
55
60
|
...findByAPI(instance),
|
|
56
61
|
...a11yAPI(instance),
|
|
57
62
|
update,
|
|
63
|
+
unmount,
|
|
58
64
|
container: instance,
|
|
59
65
|
rerender: update, // alias for `update`
|
|
60
|
-
unmount: renderer.unmount,
|
|
61
66
|
toJSON: renderer.toJSON,
|
|
62
67
|
debug: debug(instance, renderer),
|
|
63
68
|
};
|