diff --git a/src/lib/themeProvider.tsx b/src/lib/themeProvider.tsx index 2625d6aa6..3a925dbd3 100644 --- a/src/lib/themeProvider.tsx +++ b/src/lib/themeProvider.tsx @@ -55,11 +55,12 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) { // preference change (if the browser settings were changed) useEffect(() => { - const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); - mediaQuery.addEventListener('change', onPreferenceChange, false); - return () => - mediaQuery.removeEventListener('change', onPreferenceChange, false); - + const mediaQuery = window.matchMedia?.('(prefers-color-scheme: dark)'); + if (mediaQuery) { + mediaQuery.addEventListener('change', onPreferenceChange, false); + return () => + mediaQuery.removeEventListener('change', onPreferenceChange, false); + } function onPreferenceChange() { setDefaultTheme(getDefaultBrowserTheme()); } diff --git a/src/pages/App/App.test.tsx b/src/pages/App/App.test.tsx index 6a28aa26c..758d600df 100644 --- a/src/pages/App/App.test.tsx +++ b/src/pages/App/App.test.tsx @@ -3,6 +3,6 @@ import App from './App'; test('renders learn react link', () => { render(); - const page = screen.getByText(/Duality/i); - expect(page).toBeInTheDocument(); + const page = screen.getAllByText(/Duality/i); + expect(page[0]).toBeInTheDocument(); });