File tree 4 files changed +73
-1
lines changed
4 files changed +73
-1
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 @@ -95,14 +95,32 @@ public function last(string $selector): ViewAssertion
95
95
public function contains (string $ text ): ViewAssertion
96
96
{
97
97
Assert::assertStringContainsString (
98
- (string ) $ text ,
98
+ (string )$ text ,
99
99
$ this ->html ,
100
100
"Failed asserting that the text ` {$ text }` exists within ` {$ this ->html }`. "
101
101
);
102
102
103
103
return $ this ;
104
104
}
105
105
106
+ /**
107
+ * Asserts that the view, at given selector, has no content.
108
+ */
109
+ public function empty (): ViewAssertion
110
+ {
111
+ $ content = "" ;
112
+ foreach ($ this ->crawler ->getIterator () as $ node ) {
113
+ $ content .= trim ($ node ->textContent );
114
+ }
115
+
116
+ Assert::assertEmpty (
117
+ $ content ,
118
+ "Failed asserting that the text ` {$ content }` is empty. "
119
+ );
120
+
121
+ return $ this ;
122
+ }
123
+
106
124
/**
107
125
* Asserts that the view, at the **root element**, contains the given attribute value.
108
126
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ namespace Tests ;
5
+
6
+ use NunoMaduro \LaravelMojito \InteractsWithViews ;
7
+ use PHPUnit \Framework \AssertionFailedError ;
8
+ use PHPUnit \Framework \TestCase ;
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ final class AssertEmpty extends TestCase
14
+ {
15
+ use InteractsWithViews;
16
+
17
+ public function testEmpty (): void
18
+ {
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 ();
22
+ }
23
+
24
+ public function testNotEmpty (): void
25
+ {
26
+ $ this ->expectException (AssertionFailedError::class);
27
+
28
+ $ this ->assertView ('empty ' )->in ('.not-empty ' )->empty ();
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ < div >
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 >
14
+ </ div >
You can’t perform that action at this time.
0 commit comments