As seen in #53, requiring what-input in a non-DOM environment like Node (ex. for tests or server-side rendering) causes a "ReferenceError: document is not defined". The OP of that issue worked around the issue by setting up a JSDOM environment, but this approach is very expensive and isn't always tenable, especially in test runners like Jest that set up the environment from scratch for every test suite.
Here's an alternate strategy for making this work. The idea is to bail out if the document or window objects aren't defined, and instead return a mock object that behaves as if the user never did and never will interact with the page.
As seen in #53, requiring
what-input
in a non-DOM environment like Node (ex. for tests or server-side rendering) causes a "ReferenceError: document is not defined". The OP of that issue worked around the issue by setting up a JSDOM environment, but this approach is very expensive and isn't always tenable, especially in test runners like Jest that set up the environment from scratch for every test suite.Here's an alternate strategy for making this work. The idea is to bail out if the
document
orwindow
objects aren't defined, and instead return a mock object that behaves as if the user never did and never will interact with the page.