Skip to content

Commit

Permalink
Merge pull request #8 from Jamesclark32/add-toNotHaveTitle-operation
Browse files Browse the repository at this point in the history
feat: add toNotHaveTitle operation
  • Loading branch information
nunomaduro authored Feb 14, 2025
2 parents d3cdc39 + 49a3761 commit fd23bd2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Operations/ToNotHaveTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Pest\Browser\Operations;

use Pest\Browser\Contracts\Operation;

/**
* @internal
*/
final readonly class ToNotHaveTitle implements Operation
{
/**
* Creates an operation instance.
*/
public function __construct(
private string $title,
) {
//
}

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

/**
* Checks if the page does not have a title.
*/
public function toNotHaveTitle(string $title): self
{
$this->operations[] = new Operations\ToNotHaveTitle($title);

Check failure on line 55 in src/PendingTest.php

View workflow job for this annotation

GitHub Actions / Static Tests (prefer-lowest)

Method Pest\Browser\PendingTest::toNotHaveTitle() should return Pest\Browser\PendingTest but return statement is missing.

Check failure on line 55 in src/PendingTest.php

View workflow job for this annotation

GitHub Actions / Static Tests (prefer-stable)

Method Pest\Browser\PendingTest::toNotHaveTitle() should return Pest\Browser\PendingTest but return statement is missing.
}

/**
* Clicks some text on the page.
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
->clickLink('Get Started')
->assertUrlIs('https://laravel.com/docs/11.x');
});

it('should not have the title "Laravel Dusk"', function () {
visit('https://laravel.com')
->toNotHaveTitle('Laravel Dusk');
});

0 comments on commit fd23bd2

Please sign in to comment.