-
Notifications
You must be signed in to change notification settings - Fork 218
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
[Bug] Testing: TypeError: getComputedStyle(...).getPropertyValue is not a function #1505
Comments
Just a quick update, if I remove |
The error can be worked around by mocking Object.defineProperty(window, 'getComputedStyle', {
value: () => ({
getPropertyValue: (prop) => {
return '';
}
})
}); We may add feature detection if this is a common problem in customers tests. For now, we prefer to keep the code free of JSDOM-specific workarounds. |
@tsvetomir thank you! I added it to |
Thank you @tsvetomir! This just made it really easy! |
AFAICT, the mock isn't even necessary anymore. |
@brandonpittman thanks for pointing this out. The default JSDOM implementation seems to work fine in the current version. |
Worked for me! But I have a question: How do I mock more than once, with multiples values? |
@murilodevkapaz you won't be able to identify the element with the property syntax. Maybe overriding the function would help: window.getComputedStyle = (element) => {
// test for element here
return {
getPropertyValue: (prop) => {
// and for prop here
return '';
}
};
}; |
Thank you very much, sir! Helped a lot! |
I'm submitting a...
Current behavior
I'm using Jest to run our tests and we're seeing an error when the InputsModule is included for testing. Here's the error:
and a bit of the stack trace:
Here's the testbed we're using:
System:
The text was updated successfully, but these errors were encountered: