Skip to content

fails testing nested pros #589

@emacaste

Description

@emacaste

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
    );
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions