-
Notifications
You must be signed in to change notification settings - Fork 9
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 chaining queries #501
Conversation
97a0805
to
e3f36f0
Compare
3eefc90
to
d188bb7
Compare
b273764
to
e0ce6d3
Compare
e0ce6d3
to
1a3d910
Compare
Sorry, I've taken a while to get to reviewing these. I like how you've implemented the I have a couple of ideas that I'll run past you regarding the API. 1. Do we need the I guess the issue I see with this is that OK, I've convinced myself that being explicit and having a Do other's agree/disagree? 2. I've changed some of my code to use In practice, you sometimes end up writing code like this: await screen.findByRole('button', { name: 'Apply' });
await screen.getByRole('button', { name: 'Apply' }).click();
// -- or --
const applyButton = await screen.findByRole('button', { name: 'Apply' });
await applyButton.click(); But wishing that you could continue to chain await screen.findByRole('button', { name: 'Apply' }).click(); Could the concept of |
@sebinsua heh, once again, your questions/propositions follow my internal dialog/thought process pretty closely... 1.Supporting chaining without
I might try to see if I can come up with something in TypeScript that would provide exhaustive checking as to whether we've "augmented" every method that returns a 2.This also occurred to me, but the tricky bit here is that not all of the methods on I guess I could probably use the same technique I did with Edit: another point for keeping Let me know what you think about the next steps given my responses above. Do you think we should get this released on beta more or less as is so that we can iterate, or do you think it's worth seeing through these ideas? @gajus — please do let us know if you have any thoughts here as well :D |
Regarding 2., I didn't mean that the I don't really understand the implementation of this well enough to comment now, but presumably in some way |
1a3d910
to
28d9f75
Compare
Ahaaaa, ok that's an interesting idea. It still requires |
28d9f75
to
0a665c6
Compare
Just wanted to say that I'm using Playwright Test Library for the first time today, and I would really like to have this :) We've got a bunch of "page object"-style helper methods, like: export async function togglePausePane(screen: Screen) {
return screen.queryByRole("button", { name: "motion_photos_paused" }).click();
} and right now we're passing around We aren't passing |
@markerikson, that's a compelling reason to get this chaining stuff in there (as if we hadn't already convinced ourselves). I also have a project with quite a few of those sorts of helper functions that currently take a I apologize for the confusion with I'm going to go ahead and merge this as is, @sebinsua. I think we can address the additional ergonomics around
Rest assured, I still plan on implementing this and adding more inline documentation (and a bit of refactoring) to ensure everything stays maintainable :) Edit: oh yeah, I also wanted to mention that you can rest assured that the |
// Synchronous ```ts test('chaining synchronous queries', async ({screen}) => { const locator = screen.getByRole('figure').within().getByText('Some image') expect(await locator.textContent()).toEqual('Some image') }) ``` // Synchronous + Asynchronous ```ts test('chaining multiple asynchronous queries between synchronous queries', async ({screen}) => { const locator = await screen .getByTestId('modal-container') .within() .findByRole('dialog') .within() .findByRole('alert') .within() .getByRole('button', {name: 'Close'}) expect(await locator.textContent()).toEqual('Close') }) ```
0a665c6
to
8c170df
Compare
8a9d551
to
8b6761c
Compare
🎉 This PR is included in version 4.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks! It looks like this got published as part of (tbh I'm not sure I actually understand what the real difference is between those two packages.) |
Ugh, lame, sorry about that. I'll have to see why that didn't fail the build. The biggest difference is that one works with playwright the library and one works with @playwright/test the library and runner combined. Playwright has a build process with which they release many different package "flavors" from the same codebase instead of a more modular set of packages. We, therefore, need to do the same thing to some extent to support both playwright and @playwright/test. |
@markerikson, alright, I manually published @playwright-testing-library/test@4.5.0. Sorry about that. Thanks for the feedback on the confusion around the packages btw — honestly, I'd attribute some of that confusion to Playwright / Playwright Test, but I may try to clarify the difference in the readme further. |
@jrolfs thank you! as a fellow lib maintainer, I really appreciate the fast response :) |
@markerikson sure thing, let me know if you run into any other issues :) |
Implement query chaining per response to @gajus comment #498 (comment).
I think this came out to be pretty cool/useful/powerful.
Synchronous
Synchronous + Asynchronous
Todo