inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.01k stars 224 forks source link

fails testing nested pros #589

Open emacaste opened 5 months ago

emacaste commented 5 months ago

Hi folks, i have some problems with testing. It seems that pest can not handle nested props as documented. Here my test.

Any ideas?

test('screenings without query sorting are sorted by last screening date desc', function () {
    $screeningDates = [
        'firstDates'  => [
            '2024-01-01 18:00:00',
            '2024-01-02 21:00:00',
            '2024-01-03 21:00:00',
        ],
        'secondDates' => [
            '2024-01-02 18:00:00',
            '2024-01-05 21:00:00',
            '2024-01-06 21:00:00',
        ],
        'thirdDates'  => [
            '2024-01-01 21:00:00',
            '2024-01-02 21:00:00',
            '2024-01-06 21:00:00',
        ]
    ];

    $screenings = [];
    foreach ($screeningDates as $var => $screeningDate) {
        $screenings[$var] = Screening::factory()->create([
            'title' => $var
        ])
            ->each(function (Screening $screening) use ($screeningDate) {
                foreach ($screeningDate as $date) {
                    $screening->dates()->save(ScreeningDate::factory()->make([
                        'date_time' => Carbon::parse($date)
                    ]));
                }
            });
    }

    $this->withoutMiddleware();
    $response = $this->get(route('admin.web.screening.index'));
    $response->assertInertia(fn(AssertableInertia $inertia) => $inertia
        ->component('Admin/Web/Screenings/Index')
        ->has('screenings', 3, fn(AssertableInertia $inertia) => $inertia
//            ->dd('title') // OK
//            ->has('title') // Unexpected properties were found in scope [screenings.0].
//                            Failed asserting that two arrays are identical.
        )
        ->where('screenings.0.title', 'firstDates') // OK
    );
});