diff --git a/tests/BladeXTest.php b/tests/BladeXTest.php index 4f0552c..23684e6 100644 --- a/tests/BladeXTest.php +++ b/tests/BladeXTest.php @@ -70,9 +70,7 @@ public function it_compiles_a_regular_component() { BladeX::component('components.card'); - $this->assertMatchesXmlSnapshot( - view('views.regularComponent')->render() - ); + $this->assertMatchesViewSnapshot('regularComponent'); } /** @test */ @@ -80,9 +78,7 @@ public function it_compiles_a_self_closing_component() { BladeX::component('components.alert'); - $this->assertMatchesXmlSnapshot( - view('views.selfClosingComponent')->render() - ); + $this->assertMatchesViewSnapshot('selfClosingComponent'); } /** @test */ @@ -91,9 +87,15 @@ public function it_compiles_a_view_with_two_components() BladeX::component('components.card'); BladeX::component('components.textField'); - $this->assertMatchesXmlSnapshot( - view('views.twoComponents')->render() - ); + $this->assertMatchesViewSnapshot('twoComponents'); + } + + /** @test */ + public function it_compiles_a_component_that_contains_nested_components() + { + BladeX::component('components.card'); + + $this->assertMatchesViewSnapshot('nestedComponents'); } /** @test */ @@ -101,9 +103,7 @@ public function it_compiles_a_component_with_scoped_slots() { BladeX::component('components.layout'); - $this->assertMatchesXmlSnapshot( - view('views.componentWithScopedSlots')->render() - ); + $this->assertMatchesViewSnapshot('componentWithScopedSlots'); } /** @test */ @@ -111,9 +111,7 @@ public function it_compiles_a_component_with_variables() { BladeX::component('components.card'); - $this->assertMatchesXmlSnapshot( - view('views.componentWithVariables')->render() - ); + $this->assertMatchesViewSnapshot('componentWithVariables'); } /** @test */ @@ -123,8 +121,13 @@ public function it_works_with_a_global_prefix() BladeX::prefix('x'); + $this->assertMatchesViewSnapshot('globalPrefix'); + } + + protected function assertMatchesViewSnapshot(string $viewName) + { $this->assertMatchesXmlSnapshot( - view('views.globalPrefix')->render() + view("views.{$viewName}")->render() ); } } diff --git a/tests/stubs/views/views/nestedComponents.blade.php b/tests/stubs/views/views/nestedComponents.blade.php new file mode 100644 index 0000000..bc8e9fc --- /dev/null +++ b/tests/stubs/views/views/nestedComponents.blade.php @@ -0,0 +1,7 @@ + + + + Inner card + + +