Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify window exists before resetting clipboard stub #1176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boblauer
Copy link

@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.

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.

Latest deployment of this branch, based on commit 34fb721:

Sandbox Source
userEvent-dom Configuration
userEvent-react Configuration

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.

None yet

1 participant