From 691190d2b04d22c82f139fbf9c92d73477867df0 Mon Sep 17 00:00:00 2001 From: Warren Chan Date: Sun, 13 Oct 2024 17:37:44 -0400 Subject: [PATCH] add beforeEach functions back to tests --- tests/List.test.jsx | 16 ++++++++++++++++ tests/ManageList.test.jsx | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/List.test.jsx b/tests/List.test.jsx index 316406e..d8e0d79 100644 --- a/tests/List.test.jsx +++ b/tests/List.test.jsx @@ -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( diff --git a/tests/ManageList.test.jsx b/tests/ManageList.test.jsx index 252d2e4..9609a9d 100644 --- a/tests/ManageList.test.jsx +++ b/tests/ManageList.test.jsx @@ -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(