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
Guidance about mock implementation for layout related features #2751
Comments
I think there are 2 types of layout related APIs: the APIs that can be safely mocked by either doing a no-op or returning a static value and the other ones (ok, it's really vague 🤣). jsdom already provides a Scroll related APIs falls into the simple API bucket:
I am uncertain if we should use the same approach for APIs that jsdom already exposes (eg. window.innerWith, window.innerHeight, For other layout related APIs, that can't be simply replaced by a no-op or a static return value (eg. |
@pmdartus I believe a lot of people are looking for a solution to mocking those things you mentioned above, as well as others. I'm assuming that most people using jest are unknowingly introducing memory leaks into their tests by trying to mock such prototypes. One solution that I believe would be most beneficial is if there was a callback property, similar to beforeParse that would allow you to modify the window object (including prototypes) before the actual creation of the context. Perhaps the params would be the actual window object itself, as well as the utils that include the implSymbol and symbol un-wrapper function. |
I'm not sure what the difference is between this and Anyway, the inconsistent situation here is unfortunate. Here's one proposal, for a breaking change (to be introduced in a new major version):
On the technical side, I'm not sure how best to accomplish this within the webidl2js infrastructure. Maybe just install them as part of normal context creation, and delete them if |
The webidl2js side infra sounds a bit like an ad-hoc [SecureContext]. Maybe add another extended attribute that allows feature flags? |
Yeah, that's a good point. We might want to experiment with first introducing just |
To reiterate next steps for this issue: we'd like to execute the plan discussed in #2751 (comment) . The current blocker is someone making a list of all methods that could be stubbed, with links to their specs, with proposals on what their stub behavior would be. This includes ones that exist in jsdom today. And please be sure to survey closed PRs or issues to get a full sense of what people want. |
Observations
There is a lot of interest in providing mock implementations of layout related features in jsdom especially around scroll (#1422, #2626, #2332, ...). Based on the number of reactions on the different issues, 2 of the related scroll APIs are part of the top 10 most requested features.
Goal
The goal of this issue is to capture jsdom contributors and consumers' points of view on this subject and reach a consensus on how to address such features in a coherent way.
The text was updated successfully, but these errors were encountered: