Add support for puppeteer custom query handlers #352
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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$$
, orwaitForSelector
.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 usetoMatchElement
. 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.