0

I am running a Functional test in a class derived from BrowserTestBase. Line 105 of the test method has this assertion:

    $this->assertSession()->linkExists('10000003');

The test output says:

Behat\Mink\Exception\ExpectationException: Link with label 10000003 found.

identifying line 105 as the line where the exception occurred. If it found the link, why does it consider that an error?

1
  • 1
    I think the test did not find the link. Often test assertion messages are written in that way, meaning, that is the message you would expect if the test passes.
    – cilefen
    Mar 24 at 17:44

1 Answer 1

0

Aha! It appears that the WebAssert class is inconsistent in what it reports for testing errors. Sometimes it describes what shouldn't have happened: the previous error I got was described as

Input "relationship-type" cannot take "2" as a value, ...

For this latest test, however, it did the opposite, describing not what went wrong, but what the test wanted to happen. Despite the output which seemed to say the link was found, when I captured the output I discovered that the link was, in fact, not there. Others may disagree, but I think a consistent approach would be a good thing here. 😅

[Edit: this is fixed in Drupal 10, which correctly reports what caused the failure.]

4
  • 3
    Yes. I don't know if there is an existing policy not being followed, no policy at all, or no plan for any of this.
    – cilefen
    Mar 24 at 18:30
  • The documentation for the assert() method (called by WebAssert::linkExists()) states that the $message argument is the "failure message." All of the invocations of assert() by the class implementing it confirm that the message is supposed to describe the failure, rather than assert what should have happened. I will file a bug report.
    – Bob Kline
    Mar 25 at 11:48
  • I see someone beat me to the punch. It's fixed in Drupal 10. 🙌🏼
    – Bob Kline
    Mar 25 at 11:52
  • Here's the bug report: drupal.org/project/drupal/issues/3336981.
    – Bob Kline
    Mar 25 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.