@testing-library/react-native 9.0.0-alpha.0 → 9.2.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 +2 -2
- package/build/act.d.ts +3 -0
- package/build/act.js +2 -1
- package/build/act.js.map +1 -0
- package/build/cleanup.d.ts +5 -0
- package/build/cleanup.js +3 -2
- package/build/cleanup.js.map +1 -0
- package/build/fireEvent.d.ts +8 -0
- package/build/fireEvent.js +2 -1
- package/build/fireEvent.js.map +1 -0
- package/build/flushMicroTasks.d.ts +5 -0
- package/build/flushMicroTasks.js +2 -12
- package/build/flushMicroTasks.js.map +1 -0
- package/build/helpers/a11yAPI.d.ts +66 -0
- package/build/helpers/a11yAPI.js +16 -15
- package/build/helpers/a11yAPI.js.map +1 -0
- package/build/helpers/byDisplayValue.d.ts +6 -0
- package/build/helpers/byDisplayValue.js +2 -1
- package/build/helpers/byDisplayValue.js.map +1 -0
- package/build/helpers/byPlaceholderText.d.ts +6 -0
- package/build/helpers/byPlaceholderText.js +2 -1
- package/build/helpers/byPlaceholderText.js.map +1 -0
- package/build/helpers/byTestId.d.ts +6 -0
- package/build/helpers/byTestId.js +2 -1
- package/build/helpers/byTestId.js.map +1 -0
- package/build/helpers/byText.d.ts +10 -0
- package/build/helpers/byText.js +8 -5
- package/build/helpers/byText.js.map +1 -0
- package/build/helpers/debugDeep.d.ts +5 -0
- package/build/helpers/debugDeep.js +4 -1
- package/build/helpers/debugDeep.js.map +1 -0
- package/build/helpers/debugShallow.d.ts +6 -0
- package/build/helpers/debugShallow.js +4 -7
- package/build/helpers/debugShallow.js.map +1 -0
- package/build/helpers/errors.d.ts +10 -0
- package/build/helpers/errors.js +29 -9
- package/build/helpers/errors.js.map +1 -0
- package/build/helpers/filterNodeByType.d.ts +3 -0
- package/build/helpers/filterNodeByType.js +2 -1
- package/build/helpers/filterNodeByType.js.map +1 -0
- package/build/helpers/findByAPI.d.ts +17 -0
- package/build/helpers/findByAPI.js +2 -1
- package/build/helpers/findByAPI.js.map +1 -0
- package/build/helpers/format.d.ts +3 -0
- package/build/helpers/format.js +4 -3
- package/build/helpers/format.js.map +1 -0
- package/build/helpers/getByAPI.d.ts +31 -0
- package/build/helpers/getByAPI.js +4 -19
- package/build/helpers/getByAPI.js.map +1 -0
- package/build/helpers/makeA11yQuery.d.ts +13 -0
- package/build/helpers/makeA11yQuery.js +2 -1
- package/build/helpers/makeA11yQuery.js.map +1 -0
- package/build/helpers/makeQueries.d.ts +20 -0
- package/build/helpers/makeQueries.js +6 -3
- package/build/helpers/makeQueries.js.map +1 -0
- package/build/helpers/queryByAPI.d.ts +39 -0
- package/build/helpers/queryByAPI.js +3 -8
- package/build/helpers/queryByAPI.js.map +1 -0
- package/build/helpers/timers.d.ts +6 -0
- package/build/helpers/timers.js +9 -6
- package/build/helpers/timers.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.flow.js +384 -0
- package/build/index.js +2 -1
- package/build/index.js.map +1 -0
- package/build/matches.d.ts +9 -0
- package/build/matches.js +3 -2
- package/build/matches.js.map +1 -0
- package/build/{pure.js.flow → pure.d.ts} +4 -8
- package/build/pure.js +14 -31
- package/build/pure.js.map +1 -0
- package/build/render.d.ts +145 -0
- package/build/render.js +14 -10
- package/build/render.js.map +1 -0
- package/build/renderHook.d.ts +17 -0
- package/build/renderHook.js +57 -0
- package/build/renderHook.js.map +1 -0
- package/build/shallow.d.ts +8 -0
- package/build/shallow.js +3 -9
- package/build/shallow.js.map +1 -0
- package/build/waitFor.d.ts +8 -0
- package/build/waitFor.js +32 -23
- package/build/waitFor.js.map +1 -0
- package/build/waitForElementToBeRemoved.d.ts +2 -0
- package/build/waitForElementToBeRemoved.js +2 -1
- package/build/waitForElementToBeRemoved.js.map +1 -0
- package/build/within.d.ts +127 -0
- package/build/within.js +3 -2
- package/build/within.js.map +1 -0
- package/package.json +25 -15
- package/typings/index.flow.js +384 -0
- package/build/act.js.flow +0 -9
- package/build/cleanup.js.flow +0 -13
- package/build/fireEvent.js.flow +0 -127
- package/build/flushMicroTasks.js.flow +0 -23
- package/build/helpers/a11yAPI.js.flow +0 -241
- package/build/helpers/byDisplayValue.js.flow +0 -66
- package/build/helpers/byPlaceholderText.js.flow +0 -62
- package/build/helpers/byTestId.js.flow +0 -50
- package/build/helpers/byText.js.flow +0 -104
- package/build/helpers/debugDeep.js.flow +0 -16
- package/build/helpers/debugShallow.js.flow +0 -20
- package/build/helpers/errors.js.flow +0 -82
- package/build/helpers/filterNodeByType.js.flow +0 -1
- package/build/helpers/findByAPI.js.flow +0 -76
- package/build/helpers/format.js.flow +0 -10
- package/build/helpers/getByAPI.js.flow +0 -157
- package/build/helpers/makeA11yQuery.js.flow +0 -98
- package/build/helpers/makeQueries.js.flow +0 -165
- package/build/helpers/queryByAPI.js.flow +0 -166
- package/build/helpers/timers.js.flow +0 -88
- package/build/index.js.flow +0 -18
- package/build/matches.js.flow +0 -41
- package/build/render.js.flow +0 -109
- package/build/shallow.js.flow +0 -26
- package/build/types.flow.js +0 -1
- package/build/types.flow.js.flow +0 -59
- package/build/waitFor.js.flow +0 -221
- package/build/waitForElementToBeRemoved.js.flow +0 -42
- package/build/within.js.flow +0 -18
- package/typings/index.d.ts +0 -432
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import type { TextMatchOptions } from './byText';
|
|
4
|
-
import {
|
|
5
|
-
UNSAFE_getByType,
|
|
6
|
-
UNSAFE_getByProps,
|
|
7
|
-
UNSAFE_getAllByType,
|
|
8
|
-
UNSAFE_getAllByProps,
|
|
9
|
-
} from './getByAPI';
|
|
10
|
-
import { queryByTestId, queryAllByTestId } from './byTestId';
|
|
11
|
-
import { queryByText, queryAllByText } from './byText';
|
|
12
|
-
import {
|
|
13
|
-
queryByPlaceholderText,
|
|
14
|
-
queryAllByPlaceholderText,
|
|
15
|
-
} from './byPlaceholderText';
|
|
16
|
-
import { queryByDisplayValue, queryAllByDisplayValue } from './byDisplayValue';
|
|
17
|
-
import {
|
|
18
|
-
createQueryByError,
|
|
19
|
-
throwRemovedFunctionError,
|
|
20
|
-
throwRenamedFunctionError,
|
|
21
|
-
} from './errors';
|
|
22
|
-
|
|
23
|
-
export type QueryByAPI = {|
|
|
24
|
-
queryByText: (
|
|
25
|
-
name: string | RegExp,
|
|
26
|
-
queryOptions?: TextMatchOptions
|
|
27
|
-
) => ReactTestInstance | null,
|
|
28
|
-
queryAllByText: (
|
|
29
|
-
text: string | RegExp,
|
|
30
|
-
queryOptions?: TextMatchOptions
|
|
31
|
-
) => Array<ReactTestInstance>,
|
|
32
|
-
queryByPlaceholderText: (
|
|
33
|
-
placeholder: string | RegExp,
|
|
34
|
-
queryOptions?: TextMatchOptions
|
|
35
|
-
) => ReactTestInstance | null,
|
|
36
|
-
queryAllByPlaceholderText: (
|
|
37
|
-
placeholder: string | RegExp,
|
|
38
|
-
queryOptions?: TextMatchOptions
|
|
39
|
-
) => 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>,
|
|
50
|
-
|
|
51
|
-
// Unsafe aliases
|
|
52
|
-
UNSAFE_queryByType: <P>(
|
|
53
|
-
type: React.ComponentType<P>
|
|
54
|
-
) => ReactTestInstance | null,
|
|
55
|
-
UNSAFE_queryAllByType: <P>(
|
|
56
|
-
type: React.ComponentType<P>
|
|
57
|
-
) => Array<ReactTestInstance>,
|
|
58
|
-
UNSAFE_queryByProps: (props: { [string]: any }) => ReactTestInstance | null,
|
|
59
|
-
UNSAFE_queryAllByProps: (props: {
|
|
60
|
-
[string]: any,
|
|
61
|
-
}) => Array<ReactTestInstance>,
|
|
62
|
-
queryByName: () => void,
|
|
63
|
-
queryByType: () => void,
|
|
64
|
-
queryByProps: () => void,
|
|
65
|
-
queryAllByName: () => void,
|
|
66
|
-
queryAllByType: () => void,
|
|
67
|
-
queryAllByProps: () => void,
|
|
68
|
-
|
|
69
|
-
queryByPlaceholder: () => void,
|
|
70
|
-
queryAllByPlaceholder: () => void,
|
|
71
|
-
|};
|
|
72
|
-
|
|
73
|
-
export const UNSAFE_queryByType = (
|
|
74
|
-
instance: ReactTestInstance
|
|
75
|
-
): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>
|
|
76
|
-
function queryByTypeFn(type: React.ComponentType<any>) {
|
|
77
|
-
try {
|
|
78
|
-
return UNSAFE_getByType(instance)(type);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return createQueryByError(error, queryByTypeFn);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const UNSAFE_queryByProps = (
|
|
85
|
-
instance: ReactTestInstance
|
|
86
|
-
): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>
|
|
87
|
-
function queryByPropsFn(props: { [propName: string]: any }) {
|
|
88
|
-
try {
|
|
89
|
-
return UNSAFE_getByProps(instance)(props);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
return createQueryByError(error, queryByPropsFn);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const UNSAFE_queryAllByType = (
|
|
96
|
-
instance: ReactTestInstance
|
|
97
|
-
): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) => (
|
|
98
|
-
type: React.ComponentType<any>
|
|
99
|
-
) => {
|
|
100
|
-
try {
|
|
101
|
-
return UNSAFE_getAllByType(instance)(type);
|
|
102
|
-
} catch (error) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const UNSAFE_queryAllByProps = (
|
|
108
|
-
instance: ReactTestInstance
|
|
109
|
-
): ((props: {
|
|
110
|
-
[propName: string]: any,
|
|
111
|
-
}) => Array<ReactTestInstance>) => (props: { [propName: string]: any }) => {
|
|
112
|
-
try {
|
|
113
|
-
return UNSAFE_getAllByProps(instance)(props);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const queryByAPI = (instance: ReactTestInstance): QueryByAPI => ({
|
|
120
|
-
queryByTestId: queryByTestId(instance),
|
|
121
|
-
queryByText: queryByText(instance),
|
|
122
|
-
queryByPlaceholderText: queryByPlaceholderText(instance),
|
|
123
|
-
queryByDisplayValue: queryByDisplayValue(instance),
|
|
124
|
-
queryAllByTestId: queryAllByTestId(instance),
|
|
125
|
-
queryAllByText: queryAllByText(instance),
|
|
126
|
-
queryAllByPlaceholderText: queryAllByPlaceholderText(instance),
|
|
127
|
-
queryAllByDisplayValue: queryAllByDisplayValue(instance),
|
|
128
|
-
|
|
129
|
-
// Unsafe
|
|
130
|
-
UNSAFE_queryByType: UNSAFE_queryByType(instance),
|
|
131
|
-
UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),
|
|
132
|
-
UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
|
|
133
|
-
UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),
|
|
134
|
-
|
|
135
|
-
// Removed
|
|
136
|
-
queryByName: () =>
|
|
137
|
-
throwRemovedFunctionError('queryByName', 'migration-v2#removed-functions'),
|
|
138
|
-
queryAllByName: () =>
|
|
139
|
-
throwRemovedFunctionError(
|
|
140
|
-
'queryAllByName',
|
|
141
|
-
'migration-v2#removed-functions'
|
|
142
|
-
),
|
|
143
|
-
queryByType: () =>
|
|
144
|
-
throwRemovedFunctionError('queryByType', 'migration-v2#removed-functions'),
|
|
145
|
-
queryAllByType: () =>
|
|
146
|
-
throwRemovedFunctionError(
|
|
147
|
-
'queryAllByType',
|
|
148
|
-
'migration-v2#removed-functions'
|
|
149
|
-
),
|
|
150
|
-
queryByProps: () =>
|
|
151
|
-
throwRemovedFunctionError('queryByProps', 'migration-v2#removed-functions'),
|
|
152
|
-
queryAllByProps: () =>
|
|
153
|
-
throwRemovedFunctionError(
|
|
154
|
-
'queryAllByProps',
|
|
155
|
-
'migration-v2#removed-functions'
|
|
156
|
-
),
|
|
157
|
-
|
|
158
|
-
// Renamed
|
|
159
|
-
queryByPlaceholder: () =>
|
|
160
|
-
throwRenamedFunctionError('queryByPlaceholder', 'queryByPlaceholderText'),
|
|
161
|
-
queryAllByPlaceholder: () =>
|
|
162
|
-
throwRenamedFunctionError(
|
|
163
|
-
'queryAllByPlaceholder',
|
|
164
|
-
'queryAllByPlaceholderText'
|
|
165
|
-
),
|
|
166
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
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/index.js.flow
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { cleanup } from './pure';
|
|
3
|
-
import { flushMicroTasks } from './flushMicroTasks';
|
|
4
|
-
|
|
5
|
-
// If we're running in a test runner that supports afterEach
|
|
6
|
-
// then we'll automatically run cleanup afterEach test
|
|
7
|
-
// this ensures that tests run in isolation from each other
|
|
8
|
-
// if you don't like this then either import the `pure` module
|
|
9
|
-
// or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.
|
|
10
|
-
if (typeof afterEach === 'function' && !process.env.RNTL_SKIP_AUTO_CLEANUP) {
|
|
11
|
-
// eslint-disable-next-line no-undef
|
|
12
|
-
afterEach(async () => {
|
|
13
|
-
await flushMicroTasks();
|
|
14
|
-
cleanup();
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export * from './pure';
|
package/build/matches.js.flow
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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/render.js.flow
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import TestRenderer, { type ReactTestRenderer } from 'react-test-renderer'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import act from './act';
|
|
5
|
-
import { addToCleanupQueue } from './cleanup';
|
|
6
|
-
import { getByAPI, type GetByAPI } from './helpers/getByAPI';
|
|
7
|
-
import { queryByAPI, type QueryByAPI } from './helpers/queryByAPI';
|
|
8
|
-
import { findByAPI, type FindByAPI } from './helpers/findByAPI';
|
|
9
|
-
import { a11yAPI, type A11yAPI } from './helpers/a11yAPI';
|
|
10
|
-
import debugShallow from './helpers/debugShallow';
|
|
11
|
-
import debugDeep from './helpers/debugDeep';
|
|
12
|
-
|
|
13
|
-
type Options = {
|
|
14
|
-
wrapper?: React.ComponentType<any>,
|
|
15
|
-
createNodeMock?: (element: React.Element<any>) => any,
|
|
16
|
-
};
|
|
17
|
-
type TestRendererOptions = {
|
|
18
|
-
createNodeMock: (element: React.Element<any>) => any,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Renders test component deeply using react-test-renderer and exposes helpers
|
|
23
|
-
* to assert on the output.
|
|
24
|
-
*/
|
|
25
|
-
export default function render<T>(
|
|
26
|
-
component: React.Element<T>,
|
|
27
|
-
{ wrapper: Wrapper, createNodeMock }: Options = {}
|
|
28
|
-
): {
|
|
29
|
-
...FindByAPI,
|
|
30
|
-
...QueryByAPI,
|
|
31
|
-
...GetByAPI,
|
|
32
|
-
...A11yAPI,
|
|
33
|
-
update: (component: React.Element<any>) => void,
|
|
34
|
-
container: ReactTestInstance,
|
|
35
|
-
rerender: (component: React.Element<any>) => void,
|
|
36
|
-
unmount: (nextElement?: React.Element<any>) => void,
|
|
37
|
-
toJSON: () => null | ReactTestRendererJSON,
|
|
38
|
-
debug: DebugFunction,
|
|
39
|
-
} {
|
|
40
|
-
const wrap = (innerElement: React.Element<any>) =>
|
|
41
|
-
Wrapper ? <Wrapper>{innerElement}</Wrapper> : innerElement;
|
|
42
|
-
|
|
43
|
-
const renderer = renderWithAct(
|
|
44
|
-
wrap(component),
|
|
45
|
-
createNodeMock ? { createNodeMock } : undefined
|
|
46
|
-
);
|
|
47
|
-
const update = updateWithAct(renderer, wrap);
|
|
48
|
-
const instance = renderer.root;
|
|
49
|
-
const unmount = () => {
|
|
50
|
-
act(() => {
|
|
51
|
-
renderer.unmount();
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
addToCleanupQueue(unmount);
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
...getByAPI(instance),
|
|
59
|
-
...queryByAPI(instance),
|
|
60
|
-
...findByAPI(instance),
|
|
61
|
-
...a11yAPI(instance),
|
|
62
|
-
update,
|
|
63
|
-
unmount,
|
|
64
|
-
container: instance,
|
|
65
|
-
rerender: update, // alias for `update`
|
|
66
|
-
toJSON: renderer.toJSON,
|
|
67
|
-
debug: debug(instance, renderer),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function renderWithAct(
|
|
72
|
-
component: React.Element<any>,
|
|
73
|
-
options?: TestRendererOptions
|
|
74
|
-
): ReactTestRenderer {
|
|
75
|
-
let renderer: ReactTestRenderer;
|
|
76
|
-
|
|
77
|
-
act(() => {
|
|
78
|
-
renderer = TestRenderer.create(component, options);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return ((renderer: any): ReactTestRenderer);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function updateWithAct(
|
|
85
|
-
renderer: ReactTestRenderer,
|
|
86
|
-
wrap: (innerElement: React.Element<any>) => React.Element<any>
|
|
87
|
-
) {
|
|
88
|
-
return function (component: React.Element<any>) {
|
|
89
|
-
act(() => {
|
|
90
|
-
renderer.update(wrap(component));
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
interface DebugFunction {
|
|
96
|
-
(message?: string): void;
|
|
97
|
-
shallow: (message?: string) => void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function debug(
|
|
101
|
-
instance: ReactTestInstance,
|
|
102
|
-
renderer: ReactTestRenderer
|
|
103
|
-
): DebugFunction {
|
|
104
|
-
function debugImpl(message?: string) {
|
|
105
|
-
return debugDeep(renderer.toJSON(), message);
|
|
106
|
-
}
|
|
107
|
-
debugImpl.shallow = (message) => debugShallow(instance, message);
|
|
108
|
-
return debugImpl;
|
|
109
|
-
}
|
package/build/shallow.js.flow
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import { throwRemovedFunctionError } from './helpers/errors';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Renders test component shallowly using react-test-renderer/shallow
|
|
8
|
-
*/
|
|
9
|
-
export function shallowInternal(
|
|
10
|
-
instance: ReactTestInstance | React.Element<any>
|
|
11
|
-
): {| output: any |} {
|
|
12
|
-
const renderer = new ShallowRenderer();
|
|
13
|
-
|
|
14
|
-
renderer.render(React.createElement(instance.type, instance.props));
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
output: renderer.getRenderOutput(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function shallow(_: ReactTestInstance | React.Element<any>) {
|
|
22
|
-
throwRemovedFunctionError(
|
|
23
|
-
'shallow',
|
|
24
|
-
'migration-v2#removed-global-shallow-function'
|
|
25
|
-
);
|
|
26
|
-
}
|
package/build/types.flow.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/build/types.flow.js.flow
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
export type Thenable = {
|
|
4
|
-
then(resolve: () => mixed, reject?: () => mixed): mixed,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type A11yRole =
|
|
8
|
-
| 'none'
|
|
9
|
-
| 'button'
|
|
10
|
-
| 'link'
|
|
11
|
-
| 'search'
|
|
12
|
-
| 'image'
|
|
13
|
-
| 'keyboardkey'
|
|
14
|
-
| 'text'
|
|
15
|
-
| 'adjustable'
|
|
16
|
-
| 'imagebutton'
|
|
17
|
-
| 'header'
|
|
18
|
-
| 'summary'
|
|
19
|
-
| 'alert'
|
|
20
|
-
| 'checkbox'
|
|
21
|
-
| 'combobox'
|
|
22
|
-
| 'menu'
|
|
23
|
-
| 'menubar'
|
|
24
|
-
| 'menuitem'
|
|
25
|
-
| 'progressbar'
|
|
26
|
-
| 'radio'
|
|
27
|
-
| 'radiogroup'
|
|
28
|
-
| 'scrollbar'
|
|
29
|
-
| 'spinbutton'
|
|
30
|
-
| 'switch'
|
|
31
|
-
| 'tab'
|
|
32
|
-
| 'tablist'
|
|
33
|
-
| 'timer'
|
|
34
|
-
| 'toolbar';
|
|
35
|
-
|
|
36
|
-
export type A11yState = {|
|
|
37
|
-
disabled?: boolean,
|
|
38
|
-
selected?: boolean,
|
|
39
|
-
checked?: boolean | 'mixed',
|
|
40
|
-
busy?: boolean,
|
|
41
|
-
expanded?: boolean,
|
|
42
|
-
|};
|
|
43
|
-
|
|
44
|
-
export type A11yStates =
|
|
45
|
-
| 'disabled'
|
|
46
|
-
| 'selected'
|
|
47
|
-
| 'checked'
|
|
48
|
-
| 'unchecked'
|
|
49
|
-
| 'busy'
|
|
50
|
-
| 'expanded'
|
|
51
|
-
| 'collapsed'
|
|
52
|
-
| 'hasPopup';
|
|
53
|
-
|
|
54
|
-
export type A11yValue = {
|
|
55
|
-
min?: number,
|
|
56
|
-
max?: number,
|
|
57
|
-
now?: number,
|
|
58
|
-
text?: string,
|
|
59
|
-
};
|