Skip to content

Commit 27938a0

Browse files
authored
[2.x] Add ddContent method (#44)
1 parent aba528e commit 27938a0

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ $this->get('/some-route')
204204
->assertDoesntExist('div.not-here');
205205
```
206206

207+
While using either `assertContainsElement` or `assertDoesntExist` you can use the `ddContent` method to dump the content of the page to aid with debugging
208+
```
209+
$this->blade('<x-some-blade>')
210+
->assertContainsElement('#content')
211+
->ddContent();`
212+
```
213+
214+
> [!TIP]
215+
> Because this method is shared across the Test macros (response, view and component), it's technically available anywhere.
216+
207217
### Testing forms
208218
Testing forms allows using all the dom asserts from above, but has a few special helpers to help test for forms.
209219
Instead of using `->assertElementExists()` you can use `->assertFormExists()`, or the alias `assertForm()` on the test response.

ide-helper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function assertDoesntExist($selector)
5656
/** @var \Illuminate\Testing\TestResponse $instance */
5757
return $instance;
5858
}
59+
60+
public function ddContent(): void {}
5961
}
6062

6163
class TestView
@@ -113,6 +115,8 @@ public function assertDoesntExist($selector)
113115
/** @var \Illuminate\Testing\TestView $instance */
114116
return $instance;
115117
}
118+
119+
public function ddContent(): void {}
116120
}
117121

118122
class TestComponent
@@ -170,5 +174,7 @@ public function assertDoesntExist($selector)
170174
/** @var \Illuminate\Testing\TestComponent $instance */
171175
return $instance;
172176
}
177+
178+
public function ddContent(): void {}
173179
}
174180
}

src/TestComponentMacros.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,12 @@ public function assertSelectExists(): Closure
280280
return $this;
281281
};
282282
}
283+
284+
public function ddContent(): Closure
285+
{
286+
return function (): void {
287+
/** @var TestComponent $this */
288+
dd((string) $this);
289+
};
290+
}
283291
}

src/TestResponseMacros.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,12 @@ public function assertSelectExists(): Closure
280280
return $this;
281281
};
282282
}
283+
284+
public function ddContent(): Closure
285+
{
286+
return function (): void {
287+
/** @var TestResponse $this */
288+
dd($this->getContent());
289+
};
290+
}
283291
}

src/TestViewMacros.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,12 @@ public function assertSelectExists(): Closure
281281
return $this;
282282
};
283283
}
284+
285+
public function ddContent(): Closure
286+
{
287+
return function (): void {
288+
/** @var TestView $this */
289+
dd((string) $this);
290+
};
291+
}
284292
}

0 commit comments

Comments
 (0)