Skip to content

Add getByDescriptionTermΒ #140

@nicolaslohrer

Description

@nicolaslohrer

Hey @kentcdodds,

I'm totally enjoying using dom- and react-testing-library - thanks a lot!

Describe the feature you'd like:

We're using HTML description lists in our application:

<dl>
  <dt>term1</dt>
  <dd>value1</dd>
  <dt>term2</dt>
  <dd>value2</dd>
</dl>

I think it might be handy to select a dd element by its dt. In React for example, it could be used like this:

const { getByDescriptionTerm } = render(<MyDescriptionList />);
const dd = getByDescriptionTerm("term1");

Suggested implementation:

Tbh, I haven't yet looked into the internals of dom-testing-library. I suppose, it wouldn't be too different from other existing selectors. One thing that might be tricky though is that dt doesn't necessarily contain a string but might also wrap other DOM elements.

Describe alternatives you've considered:

So far, I'm just asserting that all dt and dd elements exist and have the expected content. I haven't figured out a good way to match dt and dd elements to each other in my tests though.

I'm curious to hear what you think about the idea and its feasibility!

Best,
Nicolas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions