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

feat(react 19): update react to 19, testing libraries deps to latest … #819

Closed
wants to merge 3 commits into from
Closed
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
478 changes: 250 additions & 228 deletions __tests__/auth-provider.test.tsx

Large diffs are not rendered by default.

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
20 changes: 10 additions & 10 deletions __tests__/use-auth.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import React from 'react';
import { Auth0ContextInterface, initialContext } from '../src/auth0-context';
import useAuth0 from '../src/use-auth0';
import { act, renderHook } from '@testing-library/react-hooks';
import { createWrapper } from './helpers';
import { Auth0ContextInterface, initialContext } from '../src/auth0-context';

describe('useAuth0', () => {
it('should provide the auth context', async () => {
const wrapper = createWrapper();
const {
result: { current },
waitForNextUpdate,
result: { current }
} = renderHook(() => useAuth0(), { wrapper });
await waitForNextUpdate();
expect(current).toBeDefined();
await waitFor(() => {
expect(current).toBeDefined();
});
});

it('should throw with no provider', () => {
Expand Down Expand Up @@ -42,10 +42,10 @@ describe('useAuth0', () => {
const wrapper = createWrapper({ context });
const {
result: { current },
waitForNextUpdate,
} = renderHook(() => useAuth0(context), { wrapper });
await waitForNextUpdate();
expect(current).toBeDefined();
expect(current.loginWithRedirect).not.toThrowError();
await waitFor(() => {
expect(current).toBeDefined();
expect(current.loginWithRedirect).not.toThrowError();
});
});
});
10 changes: 5 additions & 5 deletions __tests__/with-auth0.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom/extend-expect';
import React, { Component } from 'react';
import withAuth0, { WithAuth0Props } from '../src/with-auth0';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React, { Component } from 'react';
import { Auth0ContextInterface, initialContext } from '../src/auth0-context';
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
34 changes: 17 additions & 17 deletions __tests__/with-authentication-required.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import withAuthenticationRequired from '../src/with-authentication-required';
import { render, screen, waitFor, act } from '@testing-library/react';
import { Auth0Client, User } from '@auth0/auth0-spa-js';
import Auth0Provider from '../src/auth0-provider';
import '@testing-library/jest-dom';
import { act, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { Auth0ContextInterface, initialContext } from '../src/auth0-context';
import Auth0Provider from '../src/auth0-provider';
import withAuthenticationRequired from '../src/with-authentication-required';
import { defer } from './helpers';

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
Loading
Loading