Skip to content

Commit

Permalink
Merge pull request #20 from ju5t/assert-title-contains
Browse files Browse the repository at this point in the history
feat: add assertTitleContains
  • Loading branch information
nunomaduro authored Feb 15, 2025
2 parents 5c0f552 + 7e3d528 commit e76e9cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Operations/AssertTitleContains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Pest\Browser\Operations;

use Pest\Browser\Contracts\Operation;

final readonly class AssertTitleContains implements Operation
{
public function __construct(
private string $title,
) {
//
}

public function compile(): string
{
return sprintf('await expect(await page.title()).toMatch(/%s/);', $this->title);
}
}
7 changes: 7 additions & 0 deletions src/PendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public function assertTitle(string $title): self
return $this;
}

public function assertTitleContains(string $title): self
{
$this->operations[] = new Operations\AssertTitleContains($title);

return $this;
}

/**
* Checks if the page has a URL.
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Browser/Operations/AssertTitleContainsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

test('assert title contains', function () {
$url = 'https://laravel.com';

$this->visit($url)
->assertTitleContains('Laravel');
});

0 comments on commit e76e9cc

Please sign in to comment.