From 4c9f3c4ba24508c8e1c2d933f9fe0624810a6a9d Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Thu, 8 Apr 2021 21:49:29 +0200 Subject: [PATCH] Allow testing of Blade components that return closures --- .../Foundation/Testing/Concerns/InteractsWithViews.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php index 574009a68f95..faa6c64a367e 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Testing\Concerns; +use Closure; use Illuminate\Support\Facades\View as ViewFacade; use Illuminate\Support\MessageBag; use Illuminate\Support\Str; @@ -58,6 +59,10 @@ protected function component(string $componentClass, array $data = []) $view = $component->resolveView(); + if ($view instanceof Closure) { + $view = $view($data); + } + return $view instanceof View ? new TestView($view->with($component->data())) : new TestView(view($view, $component->data()));