|
5 | 5 | use Pest\Browser\Playwright\Locator; |
6 | 6 | use Pest\Browser\Playwright\Page; |
7 | 7 | use Pest\Expectation; |
| 8 | +use Pest\Mixins\Expectation as ExpectationMixin; |
8 | 9 |
|
9 | 10 | // todo: move this to Pest core |
10 | 11 | expect()->extend('toHaveTitle', function (string $title): Expectation { |
|
85 | 86 |
|
86 | 87 | expect()->extend('toHaveId', function (string $id): Expectation { |
87 | 88 |
|
88 | | - if (! $this->value instanceof Element && ! $this->value instanceof Locator) { |
89 | | - throw new InvalidArgumentException('Expected value to be an Element or Locator instance'); |
| 89 | + if (! $this->value instanceof Locator) { |
| 90 | + throw new InvalidArgumentException('Expected value to be an Locator instance'); |
90 | 91 | } |
91 | 92 |
|
92 | 93 | expect($this->value->getAttribute('id'))->toBe($id); |
|
96 | 97 |
|
97 | 98 | expect()->extend('toHaveClass', function (string $id): Expectation { |
98 | 99 |
|
99 | | - if (! $this->value instanceof Element && ! $this->value instanceof Locator) { |
100 | | - throw new InvalidArgumentException('Expected value to be an Element or Locator instance'); |
| 100 | + if (! $this->value instanceof Locator) { |
| 101 | + throw new InvalidArgumentException('Expected value to be an Locator instance'); |
101 | 102 | } |
102 | 103 |
|
103 | 104 | expect($this->value->getAttribute('class'))->toBe($id); |
|
106 | 107 | }); |
107 | 108 |
|
108 | 109 | expect()->extend('toHaveRole', function (string $role): Expectation { |
109 | | - |
110 | | - if (! $this->value instanceof Element && ! $this->value instanceof Locator) { |
111 | | - throw new InvalidArgumentException('Expected value to be an Element or Locator instance'); |
| 110 | + if (! $this->value instanceof Locator) { |
| 111 | + throw new InvalidArgumentException('Expected value to be an Locator instance'); |
112 | 112 | } |
113 | 113 |
|
114 | 114 | expect($this->value->getByRole($role))->not->toBeNull(); |
115 | 115 |
|
116 | 116 | return $this; |
117 | 117 | }); |
118 | 118 |
|
119 | | -expect()->intercept( |
120 | | - 'toBeEmpty', |
121 | | - Locator::class, |
122 | | - function (string $id): Expectation { |
123 | | - if (! $this->value instanceof Element && ! $this->value instanceof Locator) { |
124 | | - throw new InvalidArgumentException('Expected value to be an Element or Locator instance'); |
| 119 | +expect()->intercept('toBeEmpty', Locator::class, |
| 120 | + function (): ExpectationMixin { |
| 121 | + |
| 122 | + if (! $this->value instanceof Locator) { |
| 123 | + throw new InvalidArgumentException('Expected value to be an Locator instance'); |
125 | 124 | } |
126 | 125 |
|
127 | 126 | expect($this->value->textContent())->toBe(''); |
128 | 127 |
|
129 | 128 | return $this; |
130 | 129 | } |
131 | 130 | ); |
132 | | - |
133 | 131 |
|
134 | 132 | // todo: move this to Pest core end |
0 commit comments