Skip to content

Commit 0ed837a

Browse files
authored
Merge pull request #179 from biinari/fix/assertScript_without_laravel
fix: allow use of assertScript without laravel
2 parents 72cb88b + 28a6465 commit 0ed837a

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/Api/Concerns/MakesElementAssertions.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Pest\Browser\Api\Concerns;
66

7-
use Illuminate\Support\Str;
87
use Pest\Browser\Api\Webpage;
98
use PHPUnit\Framework\ExpectationFailedException;
109

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

@@ -593,4 +592,21 @@ public function waitForText(string|int|float $text): Webpage
593592

594593
return $this->assertSee($text);
595594
}
595+
596+
/**
597+
* Return true if haystack contains any of the given needles
598+
*
599+
* @param string $haystack String to look in
600+
* @param array<int, string> $needles List of needles to look for in haystack
601+
*/
602+
private static function strContainsAny(string $haystack, array $needles): bool
603+
{
604+
foreach ($needles as $needle) {
605+
if (str_contains($haystack, $needle)) {
606+
return true;
607+
}
608+
}
609+
610+
return false;
611+
}
596612
}

tests/ArchTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22

33
declare(strict_types=1);
44

5-
return;
5+
arch()
6+
->expect(['Illuminate', 'Laravel', 'Livewire'])
7+
->toOnlyBeUsedIn([
8+
Pest\Browser\Api\Livewire::class,
9+
Pest\Browser\Api\TestableLivewire::class,
10+
Pest\Browser\Cleanables\Livewire::class,
11+
Pest\Browser\Drivers\LaravelHttpServer::class,
12+
'Workbench',
13+
]);

0 commit comments

Comments
 (0)