Skip to content

Commit f0b469a

Browse files
committed
feat: adds toHaveText
1 parent f63574a commit f0b469a

8 files changed

Lines changed: 981 additions & 800 deletions

File tree

playground/composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"laravel/sail": "^1.26",
2222
"mockery/mockery": "^1.6",
2323
"nunomaduro/collision": "^8.1",
24-
"pestphp/pest": "^3.7",
25-
"pestphp/pest-plugin-laravel": "^3.1"
24+
"pestphp/pest": "^4.0",
25+
"pestphp/pest-plugin-browser": "^4.0",
26+
"pestphp/pest-plugin-laravel": "^4.0"
2627
},
2728
"autoload": {
2829
"psr-4": {
@@ -73,6 +74,6 @@
7374
"php-http/discovery": true
7475
}
7576
},
76-
"minimum-stability": "stable",
77+
"minimum-stability": "dev",
7778
"prefer-stable": true
7879
}

playground/composer.lock

Lines changed: 932 additions & 792 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
2323
<env name="BCRYPT_ROUNDS" value="4"/>
2424
<env name="CACHE_STORE" value="array"/>
25-
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
26-
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
25+
<env name="DB_CONNECTION" value="sqlite"/>
26+
<env name="DB_DATABASE" value=":memory:"/>
2727
<env name="MAIL_MAILER" value="array"/>
2828
<env name="PULSE_ENABLED" value="false"/>
2929
<env name="QUEUE_CONNECTION" value="sync"/>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<h1>
5+
Nunonation Database
6+
</h1>
7+
@endsection

playground/routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
Route::get('/test/{page}', function ($page) {
1212
return view('test-pages.'.$page);
1313
})->name('test-page');
14+
15+
Route::get('/database', function () {
16+
return view('database');
17+
})->name('database');

playground/tests/Feature/ExampleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
it('returns a successful response', function () {
6-
$response = $this->get('/');
6+
$page = page()->goto(route('database'));
77

8-
$response->assertStatus(200);
8+
expect($page->locator('h1'))->toHaveText()('Nunonation Database');
99
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
it('may have a title', function (): void {
6+
$page = page()->goto('/');
7+
8+
$locator = $page->locator('h3');
9+
10+
expect($locator)->toHaveText('Pest is a testing');
11+
});
12+
13+
it('may not have a title', function (): void {
14+
$page = page()->goto('/');
15+
16+
$locator = $page->locator('h3');
17+
18+
expect($locator)->not->toHaveText('PhpUnit is a testing framework');
19+
});

tests/Pest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
return $this;
1919
});
2020

21+
expect()->extend('toHaveText', function (string $content): Expectation {
22+
if (! $this->value instanceof Locator) {
23+
throw new InvalidArgumentException('Expected value to be an Locator instance');
24+
}
25+
26+
expect($this->value->textContent())->toContain($content);
27+
28+
return $this;
29+
});
30+
2131
expect()->extend('toBeChecked', function (): Expectation {
2232
if (! $this->value instanceof Locator) {
2333
throw new InvalidArgumentException('Expected value to be a Locator instance');
@@ -61,7 +71,7 @@
6171
});
6272

6373
expect()->extend('toBeEditable', function (): Expectation
64-
74+
{
6575
if (! $this->value instanceof Locator) {
6676
throw new InvalidArgumentException('Expected value to be a Locator instance');
6777
}

0 commit comments

Comments
 (0)