File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use PHPUnit \Framework \ExpectationFailedException ;
6+
7+ it ('passes when element has the expected value ' , function (): void {
8+ $ page = page ()->goto ('/test/form-inputs ' );
9+ expect ($ page ->locator ('input[name="email"] ' ))->toHaveValue ('john.doe@pestphp.com ' );
10+ });
11+
12+ it ('fails when element does not have the expected value ' , function (): void {
13+ $ page = page ()->goto ('/test/form-inputs ' );
14+ expect ($ page ->locator ('input[name="email"] ' ))->toHaveValue ('wrong@email.com ' );
15+ })->throws (ExpectationFailedException::class);
16+
17+ it ('passes when element does not have the value and we expect it not to ' , function (): void {
18+ $ page = page ()->goto ('/test/form-inputs ' );
19+ expect ($ page ->locator ('input[name="email"] ' ))->not ->toHaveValue ('wrong@email.com ' );
20+ });
21+
22+ it ('fails when element has the value but we expect it not to ' , function (): void {
23+ $ page = page ()->goto ('/test/form-inputs ' );
24+ expect ($ page ->locator ('input[name="email"] ' ))->not ->toHaveValue ('john.doe@pestphp.com ' );
25+ })->throws (ExpectationFailedException::class);
Original file line number Diff line number Diff line change 116116 return $ this ;
117117});
118118
119- expect ()->intercept ('toBeEmpty ' , Locator::class,
119+ expect ()->intercept (
120+ 'toBeEmpty ' ,
121+ Locator::class,
120122 function (): ExpectationMixin {
121123 expect ($ this ->value ->textContent ())->toBe ('' );
122124
123125 return $ this ;
124126 }
125127);
126128
129+ expect ()->extend ('toHaveValue ' , function (string $ id ): Expectation {
130+ if (! $ this ->value instanceof Locator) {
131+ throw new InvalidArgumentException ('Expected value to be an Locator instance ' );
132+ }
133+
134+ expect ($ this ->value ->inputValue ())->toBe ($ id );
135+
136+ return $ this ;
137+ });
127138// todo: move this to Pest core end
You can’t perform that action at this time.
0 commit comments