File tree 5 files changed +32
-45
lines changed
5 files changed +32
-45
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,16 @@ $this->assertView('welcome')->in('title')->contains('Laravel');
67
67
$this->assertView('welcome')->in('.content')->contains('Nova');
68
68
```
69
69
70
+ ### ` empty `
71
+
72
+ Asserts that the view has no text content.
73
+
74
+ _ Note: empty html nodes are not considered in this check._
75
+
76
+ ``` php
77
+ $this->assertView('empty')->in('.empty-div')->empty();
78
+ ```
79
+
70
80
### ` first `
71
81
72
82
Filters the view and returns only the first element matching the selector.
Original file line number Diff line number Diff line change @@ -104,26 +104,18 @@ public function contains(string $text): ViewAssertion
104
104
}
105
105
106
106
/**
107
- * Asserts that the view, at given selector, is empty .
107
+ * Asserts that the view, at given selector, has no content .
108
108
*/
109
109
public function empty (): ViewAssertion
110
110
{
111
- Assert::assertEmpty (
112
- $ this ->crawler ->html (),
113
- "Failed asserting that the text ` {$ this ->crawler ->html ()}` is empty. "
114
- );
115
-
116
- return $ this ;
117
- }
111
+ $ content = "" ;
112
+ foreach ($ this ->crawler ->getIterator () as $ node ) {
113
+ $ content .= trim ($ node ->textContent );
114
+ }
118
115
119
- /**
120
- * Asserts that the view, at given selector, is not empty.
121
- */
122
- public function notEmpty (): ViewAssertion
123
- {
124
- Assert::assertNotEmpty (
125
- $ this ->crawler ->html (),
126
- "Failed asserting that the text ` {$ this ->crawler ->html ()}` is not empty. "
116
+ Assert::assertEmpty (
117
+ $ content ,
118
+ "Failed asserting that the text ` {$ content }` is empty. "
127
119
);
128
120
129
121
return $ this ;
Original file line number Diff line number Diff line change @@ -17,12 +17,14 @@ final class AssertEmpty extends TestCase
17
17
public function testEmpty (): void
18
18
{
19
19
$ this ->assertView ('empty ' )->in ('.empty-div ' )->empty ();
20
+ $ this ->assertView ('empty ' )->in ('.empty-with-empty-nodes ' )->empty ();
21
+ $ this ->assertView ('empty ' )->in ('.empty-with-space ' )->empty ();
20
22
}
21
23
22
24
public function testNotEmpty (): void
23
25
{
24
26
$ this ->expectException (AssertionFailedError::class);
25
27
26
- $ this ->assertView ('button ' )->in ('.btn ' )->empty ();
28
+ $ this ->assertView ('empty ' )->in ('.not-empty ' )->empty ();
27
29
}
28
30
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
< div >
2
2
< div class ="empty-div "> </ div >
3
+ < div class ="empty-with-space ">
4
+
5
+ </ div >
6
+ < div class ="empty-with-empty-nodes ">
7
+ < span > </ span >
8
+ </ div >
9
+
10
+ < div class ="not-empty-text ">
11
+ < span > </ span >
12
+ Hello
13
+ </ div >
3
14
</ div >
You can’t perform that action at this time.
0 commit comments