Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move/remove deprecation functions #1402

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/helpers/deprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,20 @@ function deprecateQuery<QueryFn extends (...args: any) => any>(

return wrapper;
}

const warned: { [functionName: string]: boolean } = {};

// istambul ignore next: Occasionally used
export function printDeprecationWarning(functionName: string) {
if (warned[functionName]) {
return;
}

// eslint-disable-next-line no-console
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;
}
42 changes: 0 additions & 42 deletions src/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ export class ErrorWithStack extends Error {
}
}

export const createLibraryNotSupportedError = (error: unknown): Error =>
new Error(
`Currently the only supported library to search by text is "react-native".\n\n${
error instanceof Error ? error.message : ''
}`
);

export const prepareErrorMessage = (
// TS states that error caught in a catch close are of type `unknown`
// most real cases will be `Error`, but better safe than sorry
Expand Down Expand Up @@ -71,38 +64,3 @@ export function copyStackTrace(target: unknown, stackTraceSource: Error) {
);
}
}

const warned: { [functionName: string]: boolean } = {};

export function printDeprecationWarning(functionName: string) {
if (warned[functionName]) {
return;
}

// eslint-disable-next-line no-console
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
);
}