Skip to content

Commit

Permalink
[#19] Add test for PrivateRoutes but infinite redirect loop if no user
Browse files Browse the repository at this point in the history
  • Loading branch information
liamstevens111 committed Mar 21, 2023
1 parent a282779 commit e096f33
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/PrivateRoutes/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable camelcase */
import { MemoryRouter } from 'react-router-dom';

import { render, screen } from '@testing-library/react';
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';

import PrivateRoutes from '.';
import { setItem } from '../../helpers/localStorage';
import { setItem, clearItem } from '../../helpers/localStorage';

const mockTokenData = {
access_token: 'test_access_token',
Expand All @@ -21,6 +21,10 @@ const mockUserProfileData = {
};

describe('PrivateRoutes', () => {
beforeEach(() => {
clearItem('UserProfile');
});

test('renders a PrivateRoute given authenticated user', async () => {
setItem('UserProfile', { auth: mockTokenData, user: mockUserProfileData });

Expand All @@ -32,8 +36,11 @@ describe('PrivateRoutes', () => {
});

test.skip('renders a PrivateRoute', async () => {
// Infinite loop
render(<PrivateRoutes />, { wrapper: MemoryRouter });

await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading'));

expect(screen.getByTestId('loading'));
});
});

0 comments on commit e096f33

Please sign in to comment.