I'm experiencing a problem when modifying the document property with Object.defineProperty in my test code.
Specifically, the isServer() function is incorrectly evaluated as false when document changes, causing document.querySelectorAll to be executed within resetStyleSheet(), resulting in a TypeError indicating that document.querySelectorAll is not a function.
Here's the relevant code:
// my test code
Object.defineProperty(window, 'document', { value.
value: // some value here
});
// jest-styled-components/src/utils.js
const isServer = () => typeof document === 'undefined';
const resetStyleSheet = () => {
if (!isServer()) {
const scStyles = document.querySelectorAll('style[data-styled-version]')
// Other code...
}
};
This problem seems to be caused by Object.defineProperty not adding all the properties that the actual document object has in the browser environment.
I've implemented a workaround by checking if document.querySelectorAll is a function before executing it:
Hi,
I'm experiencing a problem when modifying the
document
property withObject.defineProperty
in my test code. Specifically, the isServer() function is incorrectly evaluated as false when document changes, causingdocument.querySelectorAll
to be executed withinresetStyleSheet()
, resulting in a TypeError indicating thatdocument.querySelectorAll
is not a function.Here's the relevant code:
This problem seems to be caused by Object.defineProperty not adding all the properties that the actual document object has in the browser environment.
I've implemented a workaround by checking if
document.querySelectorAll
is a function before executing it:While this works, I'm curious if there is a more optimal solution. Any suggestions are welcome.