I am sending data along with a vue in Laravel 9 with Inertia Vue 3 app. Here is the code in controller function.
public function index() {
$sliders = Slider::all();
return Inertia::render('Admin/Slider/Index', [ 'sliders' => $sliders]);
}
Inside the test file, I am testing if $sliders
count is equal. Check the following code:
public function test_render_slider_management_view_has_all_sliders() {
$user = User::factory()->create(['role' => 1]);
$random_sliders = Slider::factory()->count(5)->create();
$response = $this->actingAs($user)->get(app()->getLocale().'/admin/sliders');
$response->assertViewHas('sliders', function ($sliders) {
return count((array)$sliders) == 5;
});
}
This test gives a generic error of Failed asserting that false is true.. Upon checking $sliders
variable in the closure, its value is null
.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community