Skip to content

feat: add support for scoped queries #258

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

Merged
merged 1 commit into from
Jul 29, 2020
Merged

Conversation

smeijer
Copy link
Member

@smeijer smeijer commented Jul 29, 2020

What:
Add support for scoped queries.

Imagine having a checkout form with a shipping address and a billing address. Something like:

playground

<div>
  <form aria-labelledby="shipping-addr">
    <h1 id="shipping-addr">shipping</h1>
    <label for="input1">address</label>
    <input id="input1" name="address" placeholder="address" autocomplete="off" />
  </form>

  <form aria-labelledby="billing-addr">
    <h1 id="billing-addr">billing</h1>
    <label for="input2">address</label>
    <input id="input2" name="address" placeholder="address" autocomplete="off" />
  </form>
</div>

If we would select the "address input", playground will currently come up with a query like:

screen.getByRole('textbox', {
  name: /address/i
});

Which isn't correct. As that query will match both the shipping address as well as the billing address, and thereby it will error.

With this pull-request, playground will suggest a scoped query:

const view = within(screen.getByRole('form', {
  name: /billing/i
}));

view.getByRole('textbox', {
  name: /address/i
});

Why:
Because it's really nice!

How:

Checklist:

  • Tests
  • Ready to be merged

@smeijer smeijer self-assigned this Jul 29, 2020
@smeijer smeijer added the feature New feature or request label Jul 29, 2020
@smeijer smeijer merged commit 171f367 into develop Jul 29, 2020
@smeijer smeijer deleted the feature/scoped-queries branch July 29, 2020 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant