Skip to content

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Sep 28, 2025

Currently :

We can use and nest multiple find() methods, but, when an issue occurs it's not always obvious where exactly it is when using factories etc..

We end up with errors such as :

  Could not find a matching "div" with data: [
      "text",
      "wondering-devil" (factory data)
  ]

But, the issue is we could have numerous data providers etc-and many tests so it becomes difficult to debug.

Changes

This PR adds more context to the errors by including the selector paths ie:

  Could not find a matching "div" with data: [
      "text",
      "wondering-devil"
  ] within: .foobar > div

Which helps direct us closer to where it is.. as the selectors are the same we've entered.

To do the above I've added a TrackSelectors trait to contain that logic - and added with withSelectors in the find() method to keep track of all the selectors.

We can probably alter more assertions to be more specific - but just done a few for now.

if (! is_null($callback)) {
$elementAssert = new AssertElement($this->getContent(), $element);

$elementAssert->withSelectors($this->selectorPath, $selector);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically tells it to use the current closures selectors, and track the new selector. Seemed the most simple this way, but feel free to change :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems all good :)

@jackbayliss jackbayliss changed the title Include DOM path in certain assertions Include DOM path when nesting in assertions Sep 28, 2025
@sinnbeck
Copy link
Owner

Great idea. Will indeed make debugging way easier

@sinnbeck sinnbeck merged commit 1521c92 into sinnbeck:main Sep 30, 2025
28 checks passed
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

Successfully merging this pull request may close these issues.

2 participants