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

AssertdoesntContain asserts also for missing attribute #1153

Closed
F2210 opened this issue Jan 6, 2025 · 0 comments
Closed

AssertdoesntContain asserts also for missing attribute #1153

F2210 opened this issue Jan 6, 2025 · 0 comments

Comments

@F2210
Copy link
Contributor

F2210 commented Jan 6, 2025

Dusk Version

8.2.11

Laravel Version

11.32.0

PHP Version

8.3.14

PHPUnit Version

11.4.3

Database Driver & Version

Not applicable

Description

While using the assertAttributeDoesntContain('@xxxxxxxxxxxxxxxxxxx', 'class', 'completed') function, it asserts as false on objects without any class attributes. But in this case the expected behaviour in my opinion should be that it asserts as true when that attribute is missing. The specific value completed is missing on this elements attribute class when the attribute is missing entirely.

This behaviour would accomodate dynamic changes of classes on objects. For instance, when classes are added using javascript. When an object has no class, the class attribute will be missing. When a class is added, the class attribute itself is added as well.

Currently there are a number of functions for assertAttribute:

  • assertAttribute: checks if an attribute is found in the element and whether it's actual value is the same as the expected value
  • assertAttributeMissing (currently undocumented): Assert that the element matching the given selector is missing the provided attribute.
  • assertAttributeContains: Assert that the element matching the given selector contains the given value in the provided attribute.
  • assertAttributeDoesntContain: Assert that the element matching the given selector does not contain the given value in the provided attribute.

The last one however, also effectively evaluates whether the attribute is present. If it is missing, it also does not contain the value. But it evaluates as false when the attribute is missing. Imo, this is not expected behaviour.

  • assertAttributeMissing should check if the attribute is there, if not then ok.
  • assertAttributeDoesntContain should check if the attribute does not contain a value and is also satisfied if the attribute is not there at all.

Steps To Reproduce

Given this html content:

<!DOCTYPE html>
<html>
    <head>
        <title>Assert Attribute Doesnt Contain</title>
    </head>
    <body>
        <div id="todolist">
            <div id="todolist-item1">First</div>
            <div id="todolist-item2" class="completed">Second</div>
            <div>Third</div>
            <div>Fourth</div>
        </div>
    </body>
</html>

the following asserts would fail with Did not see expected attribute [class] within element [...]. Failed asserting that null is not null.

it('shows the todo list with item completed', function () {
        $this->browse(function (Browser $browser) {
            $browser->assertSee('To Do List')
            ->assertAttributeDoesntContain('#todolist-item1', 'class', 'completed')
        });
});
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