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

chore: missing test for assertUrlIs assertion #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Pest\Browser\Operations;
namespace Pest\Browser\Assertions;

use Pest\Browser\Contracts\Operation;

Expand All @@ -22,6 +22,8 @@ public function __construct(

public function compile(): string
{
return sprintf("await expect(page.url()).toBe('%s');", $this->url);
$pattern = str_replace('\*', '.*', preg_quote($this->url, '/'));

return sprintf('await expect(page.url()).toMatch(/%s/i);', $pattern);
}
}
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* The path to the tests.
*/
private const TEST_PATH = __DIR__.'/../.temp/e2e/runtime.spec.js';
public const TEST_PATH = __DIR__.'/../.temp/e2e/runtime.spec.js';

/**
* @param array<int, Operation> $operations
Expand Down
2 changes: 1 addition & 1 deletion src/PendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function clickLink(string $text): self
*/
public function assertUrlIs(string $url): self
{
$this->operations[] = new Operations\AssertUrlIs($url);
$this->operations[] = new Assertions\AssertUrlIs($url);

return $this;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Browser/Assertions/AssertUrlIsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Pest\Browser\Compiler;

use function Pest\Browser\visit;

it('can verify the current page URL is matching the expected one', function (): void {
visit('https://laravel.com')
->assertUrlIs('https://laravel.com');

expect(file_get_contents(Compiler::TEST_PATH))
->toContain('await expect(page.url()).toMatch(/https\:\/\/laravel\.com/i);');
});

it('can use the asterisk wildcard', function (): void {
visit('https://laravel.com/docs/11.x')
->assertUrlIs('https://laravel.com/*/11.x');

expect(file_get_contents(Compiler::TEST_PATH))
->toContain('await expect(page.url()).toMatch(/https\:\/\/laravel\.com\/.*\/11\.x/i);');
});
Loading