claudiodekker / inertia-laravel-testing

Testing helpers for https://github.com/inertiajs/inertia-laravel
MIT License
134 stars 6 forks source link

Adds support for count test #10

Closed hotmeteor closed 3 years ago

hotmeteor commented 3 years ago

This PR adds support for a ->assertInertiaCount($key, $count) test method.

Often you want to be able to test that the correct data is being returned to the browser based on filtering criteria. This new method functions like the others with a simple key / comparison signature.

// Base

$this->get(route('locations.index'))
    ->assertInertia('Locations/Index')
    ->assertInertiaHas('locations')
    ->assertInertiaCount('locations', 5);

// Filtered

$query = http_build_query(['province' => 'ON']);

$this->get(route('locations.index')."?{$query}")
    ->assertInertia('Locations/Index')
    ->assertInertiaHas('locations')
    ->assertInertiaCount('locations', 2);
claudiodekker commented 3 years ago

Nice one Adam! 👍

hotmeteor commented 3 years ago

Sorry, just realized I should have included documentation update. Want me to do that quick?

claudiodekker commented 3 years ago

That'd be great, otherwise I can pick it up later, no worries :)