Skip to content

Commit f42fa56

Browse files
committed
feat(view): Add failing test for rendering of default slot values (#1278)
1 parent dde685a commit f42fa56

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Tempest\Fixtures;
6+
7+
use Tempest\View\Elements\ViewComponentElement;
8+
use Tempest\View\ViewComponent;
9+
10+
final readonly class DefaultSlotValueComponent implements ViewComponent
11+
{
12+
public static function getName(): string
13+
{
14+
return 'x-default-slot';
15+
}
16+
17+
public function compile(ViewComponentElement $element): string
18+
{
19+
return <<<HTML
20+
<div>
21+
<x-slot>Default Value</x-slot>
22+
</div>
23+
HTML;
24+
}
25+
}

tests/Integration/View/TempestViewRendererTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ public function test_implicit_default_slot(): void
243243
);
244244
}
245245

246+
public function test_override_default_slot(): void
247+
{
248+
$this->assertStringEqualsStringIgnoringLineEndings(
249+
<<<'HTML'
250+
<div>Default Value</div>
251+
HTML,
252+
$this->render(
253+
<<<'HTML'
254+
<x-default-slot/>
255+
HTML,
256+
),
257+
);
258+
259+
$this->assertStringEqualsStringIgnoringLineEndings(
260+
<<<'HTML'
261+
<div>Custom Value</div>
262+
HTML,
263+
$this->render(
264+
<<<'HTML'
265+
<x-default-slot>Custom Value</x-default-slot>
266+
HTML,
267+
),
268+
);
269+
}
270+
246271
public function test_multiple_slots(): void
247272
{
248273
$this->assertSnippetsMatch(

0 commit comments

Comments
 (0)