forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
59 lines (50 loc) · 1.58 KB
/
errors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// @flow
export class ErrorWithStack extends Error {
constructor(message: ?string, callsite: Function) {
super(message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, callsite);
}
}
}
export const createLibraryNotSupportedError = (error: Error) =>
new Error(
`Currently the only supported library to search by text is "react-native".\n\n${error.message}`
);
export const prepareErrorMessage = (error: Error) =>
// Strip info about custom predicate
error.message.replace(/ matching custom predicate[^]*/gm, '');
export const createQueryByError = (error: Error, callsite: Function) => {
if (error.message.includes('No instances found')) {
return null;
}
throw new ErrorWithStack(error.message, callsite);
};
const warned = {};
export function printDeprecationWarning(functionName: string) {
if (warned[functionName]) {
return;
}
console.warn(`
Deprecation Warning:
Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.
`);
warned[functionName] = true;
}
export function throwRemovedFunctionError(
functionName: string,
docsRef: string
) {
throw new Error(
`"${functionName}" has been removed.\n\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`
);
}
export function throwRenamedFunctionError(
functionName: string,
newFunctionName: string
) {
throw new ErrorWithStack(
`The "${functionName}" function has been renamed to "${newFunctionName}". Please replace all occurrences.`,
throwRenamedFunctionError
);
}