From 251918a6adb013d749aea0919c36a65c18f772b1 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 5 Sep 2024 16:55:38 -0400 Subject: [PATCH] Enable test isolation I had experimented with turning this off in order to improve test performance, and apparently that ended up being merged. Now if we're to do component testing, we'll be changing things globally on the document, so isolation is very much necessary. --- src/useCallViewKeyboardShortcuts.test.tsx | 8 +++----- vitest.config.js | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/useCallViewKeyboardShortcuts.test.tsx b/src/useCallViewKeyboardShortcuts.test.tsx index 3c51df03..8d7118db 100644 --- a/src/useCallViewKeyboardShortcuts.test.tsx +++ b/src/useCallViewKeyboardShortcuts.test.tsx @@ -25,8 +25,6 @@ import { useCallViewKeyboardShortcuts } from "../src/useCallViewKeyboardShortcut // Test Explanation: // - The main objective is to test `useCallViewKeyboardShortcuts`. // The TestComponent just wraps a button around that hook. -// - We need to set `userEvent` to the `{document = window.document}` since we are testing the -// `useCallViewKeyboardShortcuts` hook here. Which is listening to window. interface TestComponentProps { setMicrophoneMuted: (muted: boolean) => void; @@ -52,7 +50,7 @@ const TestComponent: FC = ({ }; test("spacebar unmutes", async () => { - const user = userEvent.setup({ document: window.document }); + const user = userEvent.setup(); let muted = true; render( { }); test("spacebar prioritizes pressing a button", async () => { - const user = userEvent.setup({ document: window.document }); + const user = userEvent.setup(); const setMuted = vi.fn(); const onClick = vi.fn(); @@ -86,7 +84,7 @@ test("spacebar prioritizes pressing a button", async () => { }); test("unmuting happens in place of the default action", async () => { - const user = userEvent.setup({ document: window.document }); + const user = userEvent.setup(); const defaultPrevented = vi.fn(); // In the real application, we mostly just want the spacebar shortcut to avoid // scrolling the page. But to test that here in JSDOM, we need some kind of diff --git a/vitest.config.js b/vitest.config.js index 43b407b7..d9790f63 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -12,7 +12,6 @@ export default defineConfig((configEnv) => classNameStrategy: "non-scoped", }, }, - isolate: false, setupFiles: ["src/vitest.setup.ts"], coverage: { reporter: ["html", "json"],