Skip to content

Commit

Permalink
fix: theming tests (#159)
Browse files Browse the repository at this point in the history
* Fix window.matchMedia may not exist in test environment

* Fix getting of potentially more than one "Duality" text
  • Loading branch information
dib542 authored Oct 19, 2022
1 parent 20a59ec commit 983dfcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/lib/themeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/App/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import App from './App';

test('renders learn react link', () => {
render(<App />);
const page = screen.getByText(/Duality/i);
expect(page).toBeInTheDocument();
const page = screen.getAllByText(/Duality/i);
expect(page[0]).toBeInTheDocument();
});

0 comments on commit 983dfcf

Please sign in to comment.