From 94fd9662033b9b7554cb3ba96fbafcc44fc4f7b4 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Thu, 8 Apr 2021 21:58:09 +0200 Subject: [PATCH] Allow testing of Blade components that return closures (#36919) --- .../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()));