DEV Community 👩‍💻👨‍💻

im brian d
im brian d

Posted on

Laravel Assert Inertia Values

After hunting around Google and Github without finding a clear way to assert the values returned from Inertia::render the same way you can with a blade view, assertViewHas, I realized Inertia is returning a $page variable with the props. Because of this, we can drill down to the value we want to assert since assertViewHas accepts dot notation.

Post::factory(10)->create();

$this->get('/posts')
    ->assertViewHas('page.props.posts.data', function($posts) {
        return count($posts) == 10;
    });
Enter fullscreen mode Exit fullscreen mode

Note: Im paginating $posts, otherwise .data is not needed

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠