Skip to content

Commit f828aed

Browse files
Migrate tests for v4
1 parent 61f9f84 commit f828aed

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

Sample-01/tests/app/csr.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
3-
import { UserProvider } from '@auth0/nextjs-auth0/client';
3+
import { Auth0Provider } from '@auth0/nextjs-auth0';
44

55
import CSRPage from '../../app/csr/page';
66

77
describe('csr', () => {
88
it('should render without crashing', async () => {
99
render(
10-
<UserProvider user={{}}>
10+
<Auth0Provider user={{}}>
1111
<CSRPage />
12-
</UserProvider>
12+
</Auth0Provider>
1313
);
1414

1515
expect(screen.getByTestId('csr')).toBeInTheDocument();

Sample-01/tests/app/external.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
33

44
import _External from '../../app/external/page';
5-
import { UserProvider } from '@auth0/nextjs-auth0/client';
5+
import { Auth0Provider } from '@auth0/nextjs-auth0';
66

77
const External = () => (
8-
<UserProvider user={{}}>
8+
<Auth0Provider user={{}}>
99
<_External />
10-
</UserProvider>
10+
</Auth0Provider>
1111
);
1212

1313
describe('index', () => {

Sample-01/tests/app/profile.test.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { render, screen, waitFor } from '@testing-library/react';
33

4-
import { withUserProvider, mockUser } from '../fixtures';
4+
import { withAuth0Provider, mockUser } from '../fixtures';
55
import Profile from '../../app/profile/page';
66

77
describe('profile', () => {
88
it('should render without crashing', async () => {
9-
render(<Profile />, { wrapper: withUserProvider({ user: mockUser }) });
9+
render(<Profile />, { wrapper: withAuth0Provider({ user: mockUser }) });
1010

1111
expect(screen.queryByTestId('loading')).not.toBeInTheDocument();
1212
expect(screen.getByTestId('profile')).toBeInTheDocument();
@@ -16,14 +16,14 @@ describe('profile', () => {
1616
});
1717

1818
it('should render a spinner when the user is loading', async () => {
19-
render(<Profile />, { wrapper: withUserProvider({ user: undefined }) });
19+
render(<Profile />, { wrapper: withAuth0Provider({ user: undefined }) });
2020

2121
waitFor(() => screen.getByTestId('loading').toBeInTheDocument());
2222
waitFor(() => screen.queryByTestId('profile').not.toBeInTheDocument());
2323
});
2424

2525
it('should render the user profile', async () => {
26-
render(<Profile />, { wrapper: withUserProvider({ user: mockUser }) });
26+
render(<Profile />, { wrapper: withAuth0Provider({ user: mockUser }) });
2727

2828
waitFor(() => screen.queryByTestId('loading').not.toBeInTheDocument());
2929
Object.keys(mockUser).forEach(key => {

Sample-01/tests/components/Layout.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { render, screen, waitFor } from '@testing-library/react';
33

4-
import { withUserProvider } from '../fixtures';
4+
import { withAuth0Provider } from '../fixtures';
55
import Layout from '../../components/Layout';
66

77
describe('Layout', () => {
88
it('should render without crashing', async () => {
9-
render(<Layout>Text</Layout>, { wrapper: withUserProvider({ user: undefined }) });
9+
render(<Layout>Text</Layout>, { wrapper: withAuth0Provider({ user: undefined }) });
1010

1111
await waitFor(() => expect(screen.getByTestId('layout')).toBeInTheDocument());
1212
expect(screen.getByTestId('navbar')).toBeInTheDocument();

Sample-01/tests/components/NavBar.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { render, screen, waitFor } from '@testing-library/react';
33

4-
import { withUserProvider, mockUser } from '../fixtures';
4+
import { withAuth0Provider, mockUser } from '../fixtures';
55
import NavBar from '../../components/NavBar';
66

77
describe('NavBar', () => {
88
it('should render in logged out state', async () => {
9-
render(<NavBar />, { wrapper: withUserProvider({ user: undefined }) });
9+
render(<NavBar />, { wrapper: withAuth0Provider({ user: undefined }) });
1010

1111
expect(screen.getByTestId('navbar')).toBeInTheDocument();
1212
expect(screen.getByTestId('navbar-toggle')).toBeInTheDocument();
@@ -20,7 +20,7 @@ describe('NavBar', () => {
2020
});
2121

2222
it('should render in logged in state', async () => {
23-
render(<NavBar />, { wrapper: withUserProvider({ user: mockUser }) });
23+
render(<NavBar />, { wrapper: withAuth0Provider({ user: mockUser }) });
2424

2525
expect(screen.getByTestId('navbar-items').children).toHaveLength(4);
2626
expect(screen.getByTestId('navbar-home')).toBeInTheDocument();

Sample-01/tests/fixtures.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UserProvider } from '@auth0/nextjs-auth0/client';
1+
import { Auth0Provider } from '@auth0/nextjs-auth0';
22

33
export const mockUser = {
44
email: 'foo@example.com',
@@ -10,6 +10,6 @@ export const mockUser = {
1010
updated_at: null
1111
};
1212

13-
export const withUserProvider = ({ user, profileUrl } = {}) => {
14-
return props => <UserProvider {...props} user={user} profileUrl={profileUrl} />;
13+
export const withAuth0Provider = ({ user, profileUrl } = {}) => {
14+
return props => <Auth0Provider {...props} user={user} profileUrl={profileUrl} />;
1515
};

Sample-01/tests/setup.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ vi.mock('next/navigation', () => ({
1414
usePathname: () => ''
1515
}));
1616

17-
vi.mock('@auth0/nextjs-auth0', () => {
17+
vi.mock('./../lib/auth0', () => {
1818
return {
19-
getSession: () => ({
20-
user: {
21-
sub: 'bob'
22-
}
23-
}),
24-
getAccessToken: () => 'access_token',
25-
withApiAuthRequired: handler => handler,
26-
withPageAuthRequired: page => () => page()
19+
auth0: {
20+
getSession: () => ({
21+
user: {
22+
sub: 'bob'
23+
}
24+
}),
25+
getAccessToken: () => 'access_token',
26+
}
2727
};
28-
});
28+
});

0 commit comments

Comments
 (0)