Skip to content

Commit e1ff73f

Browse files
committed
refactor: clean up test setup
1 parent 47604cc commit e1ff73f

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

site/src/hooks/useClipboard.test-setup.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ function renderUseClipboard(textToCopy: string) {
104104

105105
type ScheduleConfig = Readonly<{ isHttps: boolean }>;
106106

107-
/**
108-
* Unconventional test setup, but we need two separate instances of the
109-
* MockClipboard (one for HTTP and one for HTTPS).
110-
*
111-
* All beforeAll and afterEach hooks must be tied to the specific instance, or
112-
* else you get shared mutable state, and test cases interfering with each
113-
* other. Test isolation is especially important for this test file
114-
*/
115107
export function scheduleClipboardTests({ isHttps }: ScheduleConfig) {
116108
const mockClipboardInstance = makeMockClipboard(isHttps);
117109

@@ -121,10 +113,8 @@ export function scheduleClipboardTests({ isHttps }: ScheduleConfig) {
121113
...originalNavigator,
122114
clipboard: mockClipboardInstance,
123115
}));
124-
});
125116

126-
if (!isHttps) {
127-
beforeAll(() => {
117+
if (!isHttps) {
128118
// Not the biggest fan of exposing implementation details like this, but
129119
// making any kind of mock for execCommand is really gnarly in general
130120
global.document.execCommand = jest.fn(() => {
@@ -141,8 +131,8 @@ export function scheduleClipboardTests({ isHttps }: ScheduleConfig) {
141131

142132
return copySuccessful;
143133
});
144-
});
145-
}
134+
}
135+
});
146136

147137
afterEach(() => {
148138
mockClipboardInstance.setMockText("");

0 commit comments

Comments
 (0)