Skip to content

Commit

Permalink
refactor: remove explicit return types for functional components in t…
Browse files Browse the repository at this point in the history
…ests and providers
  • Loading branch information
leefreemanxyz committed Dec 23, 2024
1 parent 0d87378 commit fb5e5fe
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion __tests__/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const createWrapper = ({
}: Partial<Auth0ProviderOptions> = {}) => {
return function Wrapper({
children,
}: PropsWithChildren<Record<string, unknown>>): JSX.Element {
}: PropsWithChildren<Record<string, unknown>>) {
return (
<Auth0Provider domain={domain} clientId={clientId} {...opts}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('In a Node SSR environment', () => {
ReactDOMServer.renderToString(
<Auth0Provider clientId="__client_id__" domain="__domain__">
<Auth0Context.Consumer>
{(value): JSX.Element => {
{(value) => {
({ isLoading, isAuthenticated, user, loginWithRedirect } = value);
return <div>App</div>;
}}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/with-auth0.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import withAuth0, { WithAuth0Props } from '../src/with-auth0';
describe('withAuth0', () => {
it('should wrap a class component', () => {
class MyComponent extends Component<WithAuth0Props> {
render(): JSX.Element {
render() {
return <>hasAuth: {`${!!this.props.auth0}`}</>;
}
}
Expand All @@ -19,7 +19,7 @@ describe('withAuth0', () => {
it('should wrap a class component and provide context', () => {
const context = React.createContext<Auth0ContextInterface>(initialContext);
class MyComponent extends Component<WithAuth0Props> {
render(): JSX.Element {
render() {
return <>hasAuth: {`${!!this.props.auth0}`}</>;
}
}
Expand Down
24 changes: 12 additions & 12 deletions __tests__/with-authentication-required.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockClient = jest.mocked(new Auth0Client({ clientId: '', domain: '' }));
describe('withAuthenticationRequired', () => {
it('should block access to a private component when not authenticated', async () => {
mockClient.getUser.mockResolvedValue(undefined);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent);
render(
<Auth0Provider clientId="__test_client_id__" domain="__test_domain__">
Expand All @@ -27,7 +27,7 @@ describe('withAuthenticationRequired', () => {

it('should allow access to a private component when authenticated', async () => {
mockClient.getUser.mockResolvedValue({ name: '__test_user__' });
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent);
await act(() => {
render(
Expand All @@ -49,8 +49,8 @@ describe('withAuthenticationRequired', () => {
const deferred = defer<User | undefined>();
mockClient.getUser.mockResolvedValue(deferred.promise);

const MyComponent = (): JSX.Element => <>Private</>;
const OnRedirecting = (): JSX.Element => <>Redirecting</>;
const MyComponent = () => <>Private</>;
const OnRedirecting = () => <>Redirecting</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
onRedirecting: OnRedirecting,
});
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('withAuthenticationRequired', () => {
mockClient.loginWithRedirect.mockImplementationOnce(async () => {
callOrder.push('loginWithRedirect');
});
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const OnBeforeAuthentication = jest
.fn()
.mockImplementationOnce(async () => {
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('withAuthenticationRequired', () => {

it('should pass additional options on to loginWithRedirect', async () => {
mockClient.getUser.mockResolvedValue(undefined);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
loginOptions: {
fragment: 'foo',
Expand All @@ -134,7 +134,7 @@ describe('withAuthenticationRequired', () => {

it('should merge additional appState with the returnTo', async () => {
mockClient.getUser.mockResolvedValue(undefined);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
loginOptions: {
appState: {
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('withAuthenticationRequired', () => {

it('should accept a returnTo function', async () => {
mockClient.getUser.mockResolvedValue(undefined);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
returnTo: () => '/foo',
});
Expand All @@ -184,9 +184,9 @@ describe('withAuthenticationRequired', () => {

it('should call loginWithRedirect only once even if parent state changes', async () => {
mockClient.getUser.mockResolvedValue(undefined);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent);
const App = ({ foo }: { foo: number }): JSX.Element => (
const App = ({ foo }: { foo: number }) => (
<div>
{foo}
<Auth0Provider clientId="__test_client_id__" domain="__test_domain__">
Expand All @@ -210,7 +210,7 @@ describe('withAuthenticationRequired', () => {
mockClient.getUser.mockResolvedValueOnce({ name: '__test_user__' });
mockClient.getUser.mockResolvedValueOnce(undefined);
const context = React.createContext<Auth0ContextInterface>(initialContext);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
context,
});
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('withAuthenticationRequired', () => {
mockClient.getUser.mockResolvedValueOnce(undefined);
mockClient.getUser.mockResolvedValueOnce({ name: '__test_user__' });
const context = React.createContext<Auth0ContextInterface>(initialContext);
const MyComponent = (): JSX.Element => <>Private</>;
const MyComponent = () => <>Private</>;
const WrappedComponent = withAuthenticationRequired(MyComponent, {
context,
});
Expand Down
2 changes: 1 addition & 1 deletion src/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
*
* Provides the Auth0Context to its child components.
*/
const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
const Auth0Provider = (opts: Auth0ProviderOptions) => {
const {
children,
skipRedirectCallback,
Expand Down
4 changes: 2 additions & 2 deletions src/with-auth0.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const withAuth0 = <P extends WithAuth0Props>(
Component: ComponentType<P>,
context = Auth0Context
): ComponentType<Omit<P, keyof WithAuth0Props>> => {
return function WithAuth(props): JSX.Element {
return function WithAuth(props) {
return (
<context.Consumer>
{(auth: Auth0ContextInterface): JSX.Element => (
{(auth: Auth0ContextInterface) => (
<Component {...(props as P)} auth0={auth} />
)}
</context.Consumer>
Expand Down
8 changes: 4 additions & 4 deletions src/with-authentication-required.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Auth0Context, {
/**
* @ignore
*/
const defaultOnRedirecting = (): JSX.Element => <></>;
const defaultOnRedirecting = () => <></>;

/**
* @ignore
*/
const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */};
const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */ };

/**
* @ignore
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface WithAuthenticationRequiredOptions {
*
* Render a message to show that the user is being redirected to the login.
*/
onRedirecting?: () => JSX.Element;
onRedirecting?: () => React.JSX.Element;
/**
* ```js
* withAuthenticationRequired(Profile, {
Expand Down Expand Up @@ -98,7 +98,7 @@ const withAuthenticationRequired = <P extends object>(
Component: ComponentType<P>,
options: WithAuthenticationRequiredOptions = {}
): FC<P> => {
return function WithAuthenticationRequired(props: P): JSX.Element {
return function WithAuthenticationRequired(props: P) {
const {
returnTo = defaultReturnTo,
onRedirecting = defaultOnRedirecting,
Expand Down

0 comments on commit fb5e5fe

Please sign in to comment.