Skip to content

Conversation

@boblauer
Copy link
Contributor

@boblauer boblauer commented Nov 3, 2023

What:

Ensure that globalThis.window exists before resetting/detaching the clipboard stub in the afterEach/afterAll hooks.

Why:

Using this library in a test suite does not imply that every test in the suite will run in a browser-like environment. I have a test suite that initializes jsdom to test client-side code, but then tears it down after the tests. I wanted to use this library, but I couldn't because as soon as a test ran that didn't initialize jsdom, this afterEach hook would run and throw an error because globalThis.window was undefined.

How:

Verify that globalThis.window exists inside of the hook. I didn't want to put the check inside of resetClipboardStubOnView because this file is meant to be run in a browser-like environment, so it seemed most appropriate to put the check inside the hook.

Checklist:

  • [N/A] Documentation
  • [N/A] Tests
  • Ready to be merged

There were no existing tests related to the afterEach/afterAll hooks, and I wasn't sure how to go about writing a test for those, so this code does not have any unit tests around it.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 3, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@boblauer boblauer requested a review from abarajithan July 1, 2024 12:40
@boblauer
Copy link
Contributor Author

Closing, I'm assuming this won't ever be merged.

@boblauer boblauer closed this Nov 20, 2024
@ph-fritsche ph-fritsche reopened this Jan 13, 2025
@ph-fritsche ph-fritsche self-assigned this Feb 4, 2025
@ph-fritsche ph-fritsche force-pushed the pr/ensure-window-exists-before-resetting-clipboard branch from 77489f1 to 14d62a0 Compare February 4, 2025 16:45
@ph-fritsche ph-fritsche merged commit 4f882e6 into testing-library:main Feb 4, 2025
3 checks passed
@valentinpalkovic
Copy link

Is there any chance to get this fix released soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants