-
Notifications
You must be signed in to change notification settings - Fork 404
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
Support Puppeteer #201
Comments
This seems like something that would be good to look into. I have zero experience with puppeteer, but would love to see this tackled and in the process to get to know more about it. As for the approach to implement it, if it can be handled internally in a way that does not add significant complexity to the existing code, while allowing for this proxying to happen as transparently as possible, then I'm all for it. Alternatively, I'd also be open to this be in a separate repo. Please, feel free to explore making a PR to add support for this as you see fit, or starting a more technical discussion here of what this would entail, if you're in doubt it would be accepted. |
For instance, an acceptable alternative that seems viable from what you mention the issue is right now, is that we could require all matchers to not consume the received The thing that makes me wonder if it would be that simple is that you mention something along the lines of matchers being async with puppeteer, so not sure if that poses an additional difficulty in making the same matchers implementation be compatible with both the sync and async way of calling them. |
@sandinmyjoints do you have any comments on this? I'm trying to figure out if there can be some actionable in the future, or else close the issue. |
I've been playing with this idea recently, and I made a POC of this feature here. The basic idea is to use sync then-able function to evaluate the element in regular Jest environment, but use Here's a simplified version of the code. function toHaveAttribute(htmlElement, ...args) {
return evaluate(htmlElement, ...args).then(pass => ({
pass,
message: () => "Oops"
}));
} The gotcha here is that everything passed to and returned from I use
One thing left there is how to handle Another option would be to export another function like WDYT? Curious to hear your thoughts :). |
Unfortunately if we use the same API and try to hide the async Promises from non-Puppeteer users, we run into issues with |
I'm not sure I follow this. How does |
As far as I understand by looking at the code, |
Describe the feature you'd like:
Matchers that work when running tests in Puppeteer.
Suggested implementation:
Puppeteer methods return ElementHandles that are proxies for elements in the DOM in the browser it's communicating with. jest-dom currently expects actual HTMLElements. So at a high level, it seems like an implementation approach could be to proxy the methods jest-dom is calling on the HTMLElements into calls to, say, ElementHandle
.evaluate. ElementHandle's methods are all async, so the matchers would need to be async -- perhaps this could be done with a parallel set of async matchers to the existing (sync) matchers.
Describe alternatives you've considered:
Teachability, Documentation, Adoption, Migration Strategy:
This would likely be straightforward: simply mentioning in the docs that jest-dom is compatible with puppeteer, and noting that the async versions of the matchers would need to be used.
The text was updated successfully, but these errors were encountered: