Skip to content
Merged
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
20 changes: 18 additions & 2 deletions src/Api/Concerns/MakesElementAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Pest\Browser\Api\Concerns;

use Illuminate\Support\Str;
use Pest\Browser\Api\Webpage;
use PHPUnit\Framework\ExpectationFailedException;

Expand Down Expand Up @@ -155,7 +154,7 @@ public function assertCount(string $selector, int $expected): Webpage
*/
public function assertScript(string $expression, mixed $expected = true): Webpage
{
if (! Str::contains($expression, ['===', '!==', '==', '!=', '>', '<', '>=', '<=', '&&', '||']) && ! Str::startsWith($expression, 'return ') && ! Str::startsWith($expression, 'function')) {
if (! self::strContainsAny($expression, ['===', '!==', '==', '!=', '>', '<', '>=', '<=', '&&', '||']) && ! str_starts_with($expression, 'return ') && ! str_starts_with($expression, 'function')) {
$expression = "function() { return {$expression}; }";
}

Expand Down Expand Up @@ -567,4 +566,21 @@ public function waitForText(string|int|float $text): Webpage

return $this->assertSee($text);
}

/**
* Return true if haystack contains any of the given needles
*
* @param string $haystack String to look in
* @param array<int, string> $needles List of needles to look for in haystack
*/
private static function strContainsAny(string $haystack, array $needles): bool
{
foreach ($needles as $needle) {
if (str_contains($haystack, $needle)) {
return true;
}
}

return false;
}
}
10 changes: 9 additions & 1 deletion tests/ArchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

declare(strict_types=1);

return;
arch()
->expect(['Illuminate', 'Laravel', 'Livewire'])
->toOnlyBeUsedIn([
Pest\Browser\Api\Livewire::class,
Pest\Browser\Api\TestableLivewire::class,
Pest\Browser\Cleanables\Livewire::class,
Pest\Browser\Drivers\LaravelHttpServer::class,
'Workbench',
]);