Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
For javascript testing states and similar functionality it could be helpful to have assertions that check whether a certain form element or element is visible.
On the other hand, adding an infinite amount of assertions makes it harder to choose from, and also doesn't teach people, how to leverage the underlying APIs.
Proposed resolution
Discuss to which level of detail we want to add assertions and helpers.
Comments
Comment #2
jibranWe had infinite amount of assertions in simpletests and we never ran into this problem there but that is not the point here.
I want us to move on from web test base approach in which we simulate request and response and then on that simulated results we perform some assertions.
I want us to adapt behaviour driven approach in which we test the behaviour of a user not the request and response simulation. Now that we have been running tests using headless browser we can achieve that easily but we have to change our mind set for this. The benefits of this apporoch can be seen in #2711963: Modernized ToolbarIntegrationTest. It improved the readability but the most important thing here is that it improved the adaption of JTB in contrib. I have seen many patches in contrib following this pattern now.
I think by adding the following methods:
we'll improve the readability, adaption and usage of JTB. This well lessen the steepness of test writing learning curve as well.
Comment #5
idebr CreditAttribution: idebr at iO commentedCan this be closed as a duplicate of #2702233: [backport] Add JavaScript tests for Form API #states: required, visible, invisible, expanded, checked, unchecked, since that patch contains the assertions mentioned in #2?