Skip to content

Commit 0841cc8

Browse files
committed
refactor: simplify validation in expectation extensions to require only Locator instance
1 parent 7379126 commit 0841cc8

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

tests/Pest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use Pest\Browser\Playwright\Element;
65
use Pest\Browser\Playwright\Locator;
76
use Pest\Browser\Playwright\Page;
87
use Pest\Expectation;
@@ -20,8 +19,8 @@
2019

2120
expect()->extend('toBeChecked', function (): Expectation {
2221

23-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
24-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
22+
if (! $this->value instanceof Locator) {
23+
throw new InvalidArgumentException('Expected value to be a Locator instance');
2524
}
2625

2726
expect($this->value->isChecked())->toBeTrue();
@@ -31,8 +30,8 @@
3130

3231
expect()->extend('toBeVisible', function (): Expectation {
3332

34-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
35-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
33+
if (! $this->value instanceof Locator) {
34+
throw new InvalidArgumentException('Expected value to be a Locator instance');
3635
}
3736

3837
expect($this->value->isVisible())->toBeTrue();
@@ -42,8 +41,8 @@
4241

4342
expect()->extend('toBeEnabled', function (): Expectation {
4443

45-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
46-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
44+
if (! $this->value instanceof Locator) {
45+
throw new InvalidArgumentException('Expected value to be a Locator instance');
4746
}
4847

4948
expect($this->value->isEnabled())->toBeTrue();
@@ -53,8 +52,8 @@
5352

5453
expect()->extend('toBeDisabled', function (): Expectation {
5554

56-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
57-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
55+
if (! $this->value instanceof Locator) {
56+
throw new InvalidArgumentException('Expected value to be a Locator instance');
5857
}
5958

6059
expect($this->value->isDisabled())->toBeTrue();
@@ -64,8 +63,8 @@
6463

6564
expect()->extend('toBeEditable', function (): Expectation {
6665

67-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
68-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
66+
if (! $this->value instanceof Locator) {
67+
throw new InvalidArgumentException('Expected value to be a Locator instance');
6968
}
7069

7170
expect($this->value->isEditable())->toBeTrue();
@@ -75,8 +74,8 @@
7574

7675
expect()->extend('toBeHidden', function (): Expectation {
7776

78-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
79-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
77+
if (! $this->value instanceof Locator) {
78+
throw new InvalidArgumentException('Expected value to be a Locator instance');
8079
}
8180

8281
expect($this->value->isHidden())->toBeTrue();

0 commit comments

Comments
 (0)