Skip to content
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

add method to query child elements #1579

Open
jelhan opened this issue May 23, 2022 · 0 comments
Open

add method to query child elements #1579

jelhan opened this issue May 23, 2022 · 0 comments

Comments

@jelhan
Copy link
Contributor

jelhan commented May 23, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant