Skip to content

Commit d341859

Browse files
committed
Adds failing test for using $value in :foreach="$iterable as $value"
1 parent 0c553d4 commit d341859

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/Integration/View/ViewComponentTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,39 @@ public function test_nested_table_components(): void
791791
HTML, $html);
792792
}
793793

794+
public function test_loop_variable_can_be_used_within_the_looped_tag(): void
795+
{
796+
$this->registerViewComponent(
797+
'x-some-component-with-loop',
798+
<<<'HTML'
799+
<a :foreach="$items as $item" :href="$item->uri">
800+
{{ $item->title }}
801+
</a>
802+
HTML,
803+
);
804+
805+
$html = $this->render(
806+
view(
807+
<<<'HTML'
808+
<x-some-component-with-loop :items="$this->items" />
809+
HTML,
810+
)->data(items: [
811+
new class {
812+
public string $title = 'Item 1';
813+
public string $uri = '/item-1';
814+
},
815+
new class {
816+
public string $title = 'Item 2';
817+
public string $uri = '/item-2';
818+
},
819+
]
820+
));
821+
822+
$this->assertSnippetsMatch(<<<'HTML'
823+
<a href="/item-1">Item 1</a><a href="/item-2">Item 2</a>
824+
HTML, $html);
825+
}
826+
794827
private function assertSnippetsMatch(string $expected, string $actual): void
795828
{
796829
$expected = str_replace([PHP_EOL, ' '], '', $expected);

0 commit comments

Comments
 (0)