Skip to content
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

Add support for puppeteer custom query handlers #352

Closed
wants to merge 1 commit into from

Conversation

jharwig
Copy link

@jharwig jharwig commented May 21, 2020

feat: Support puppeteer custom queries in toMatchElement
fix: Support xpath queries and hidden/visible options in .not.toMatchElement
fix: Support hidden option in toMatchElement
fix: timeout supported in toMatchElement Fixes #324
fix: hidden/visible set in default options is used by toMatchElement Fixes #285
breaking change: Removed node 8 support for jest-puppeteer development

Not confirmed, but might solve #296

Summary

Puppeteer has added (experimental) support for adding custom query handlers. This PR allows any custom queries that are defined to be used in toMatchElement the same way they work in $$, or waitForSelector.

https://github.com/smooth-code/jest-puppeteer/blob/422938a2bc7d6ff933ec013ded3b83f3aaf0a946/examples/create-react-app/integration/app.test.js#L17

To make this happen, this PR changes the element selection implementation in toMatchElement to use the puppeteer query APIs instead. Also updates notToMatchElement to use toMatchElement. Doing so adds xpath, and hidden/visible support there and aligns it more fully with actually negating a match.

This code change doesn't break existing compatibility with puppeteer, but updating puppeteer here to 3 requires node 10 (so the node 8 travis plan was removed.) If the peer version of puppeteer is >= 3.0.3 custom handlers will just work, but puppeteer < 3 will work as is.

Test plan

All existing tests pass, and added more tests around custom handlers and xpath queries. There is also an example custom query handler is in the example/ project. The dependencies in the example project were changed to file references to test local changes in packages.

tests

Screen Shot 2020-05-21 at 10 24 27 AM

fix: Support xpath queries and hidden/visible in `.not.toMatchElement`
fix: Support hidden option in toMatchElement

Changes the element selection implementation in toMatchElement to use
the puppeteer query APIs. Allows customQueryHandlers defined in puppeteer
to be used in toMatchElement calls. An example is in the example/ folder.
@UziTech
Copy link
Contributor

UziTech commented Apr 8, 2021

could you rebase this PR on the latest changes in master?

Copy link
Contributor

@UziTech UziTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants