Skip to content

Commit

Permalink
add beforeEach functions back to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenchan13 committed Oct 13, 2024
1 parent 416b969 commit 691190d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/List.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import { MemoryRouter } from 'react-router-dom';
import { List } from '../src/views/List';
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData';

beforeEach(() => {
Object.defineProperty(window, 'localStorage', {
value: {
getItem: vi.fn((key) => {
if (key === 'tcl-shopping-list-path') {
return '/groceries';
}
return null;
}),
setItem: vi.fn(),
clear: vi.fn(),
},
writable: true,
});
});

describe('List Component', () => {
test('renders the shopping list name, search field, and all list items from the data prop', () => {
render(
Expand Down
16 changes: 16 additions & 0 deletions tests/ManageList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ import { render, screen } from '@testing-library/react';
import { ManageList } from '../src/views/ManageList';
import { MemoryRouter } from 'react-router-dom';

beforeEach(() => {
Object.defineProperty(window, 'localStorage', {
value: {
getItem: vi.fn((key) => {
if (key === 'tcl-shopping-list-path') {
return '/groceries';
}
return null;
}),
setItem: vi.fn(),
clear: vi.fn(),
},
writable: true,
});
});

describe('ManageList Component', () => {
test('renders AddItems component with submit button and radio buttons', () => {
render(
Expand Down

0 comments on commit 691190d

Please sign in to comment.