Skip to content

Commit

Permalink
assert attr missing (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziadoz authored Feb 2, 2024
1 parent 0374881 commit bd1b16c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,27 @@ public function assertAttribute($selector, $attribute, $value)
return $this;
}

/**
* Assert that the element matching the given selector is missing the provided attribute.
*
* @param string $selector
* @param string $attribute
* @return $this
*/
public function assertAttributeMissing($selector, $attribute)
{
$fullSelector = $this->resolver->format($selector);

$actual = $this->resolver->findOrFail($selector)->getAttribute($attribute);

PHPUnit::assertNull(
$actual,
"Saw unexpected attribute [{$attribute}] within element [{$fullSelector}]."
);

return $this;
}

/**
* Assert that the element matching the given selector contains the given value in the provided attribute.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,35 @@ public function test_assert_attribute()
}
}

public function test_assert_attribute_missing()
{
$driver = m::mock(stdClass::class);

$element = m::mock(stdClass::class);
$element->shouldReceive('getAttribute')->with('bar')->andReturn(
null,
'joe',
);

$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('format')->with('foo')->andReturn('Foo');
$resolver->shouldReceive('findOrFail')->with('foo')->andReturn($element);

$browser = new Browser($driver, $resolver);

$browser->assertAttributeMissing('foo', 'bar');

try {
$browser->assertAttributeMissing('foo', 'bar');
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString(
'Saw unexpected attribute [bar] within element [Foo].',
$e->getMessage()
);
}
}

public function test_assert_attribute_contains()
{
$driver = m::mock(stdClass::class);
Expand Down

0 comments on commit bd1b16c

Please sign in to comment.