Skip to content

add method to query child elements #1579

@jelhan

Description

@jelhan

For readability it would be awesome, if we could chain .dom() method calls:

assert
  .dom('h1")
  .exists('renders a first-level headline')
  .hasText('My Blog Post', 'renders title of blog post as headline')
  .dom('a')
  .exists('renders a link inside the headline')
  .hasAttribute('href', '/posts/1', 'link target is the page for the post')
  .hasText('My Blog Post', 'link has title of the blog post as text')

This would be the same as currently:

assert
  .dom('h1")
  .exists('renders a first-level headline')
  .hasText('My Blog Post', 'renders title of blog post as headline')

assert.dom('a', 'h1')
  .exists('renders a link inside the headline')
  .hasAttribute('href', '/posts/1', 'link target is the page for the post')
  .hasText('My Blog Post', 'link has title of the blog post as text')

Main pain point with this one is that it gets messy if the main selector is not as easy as 'h1'.

I'm not fully convinced by the API I proposed above. It would be best if the API would allow asserting against multiple childs of a main element using chaining. A good example is a form element, which we want to assert against label and input child elements. This is not supported using chaining by the API proposed above. Maybe someone else has a better idea, which would support even that.

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