-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add assertVisible and assertMissing assertions
- Loading branch information
1 parent
2bc935f
commit 27bcdea
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\Operations; | ||
|
||
use Pest\Browser\Contracts\Operation; | ||
|
||
final class AssertMissing implements Operation | ||
{ | ||
/** | ||
* Creates an operation instance. | ||
*/ | ||
public function __construct( | ||
private string $selector, | ||
) { | ||
// | ||
} | ||
|
||
/** | ||
* Compile the operation. | ||
*/ | ||
public function compile(): string | ||
{ | ||
$escapedSelector = str_replace("'", "\'", $this->selector); | ||
|
||
return "await expect(page.locator('{$escapedSelector}')).toBeHidden();"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\Operations; | ||
|
||
use Pest\Browser\Contracts\Operation; | ||
|
||
final class AssertVisible implements Operation | ||
{ | ||
/** | ||
* Creates an operation instance. | ||
*/ | ||
public function __construct( | ||
private string $selector, | ||
) { | ||
// | ||
} | ||
|
||
/** | ||
* Compile the operation. | ||
*/ | ||
public function compile(): string | ||
{ | ||
$escapedSelector = str_replace("'", "\'", $this->selector); | ||
|
||
return "await expect(page.locator('{$escapedSelector}')).toBeVisible();"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
|
||
describe('assert missing', function () { | ||
it('passes when the given element is not visible', function () { | ||
$this->visit('https://laravel.com') | ||
->assertMissing('.DocSearch-Button-Keys'); | ||
}); | ||
|
||
it('fails when the given element is visible', function () { | ||
$this->visit('https://laravel.com') | ||
->assertMissing('body'); | ||
})->throws(ProcessFailedException::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
|
||
describe('assert visible', function () { | ||
it('passes when the given element is visible', function () { | ||
$this->visit('https://laravel.com') | ||
->assertVisible('body'); | ||
}); | ||
|
||
it('fails when the given element is not visible', function () { | ||
$this->visit('https://laravel.com') | ||
->assertVisible('.DocSearch-Button-Keys'); | ||
})->throws(ProcessFailedException::class); | ||
}); |