newbie360's avatar

Pest HTTP test use route helper instead static path

Route::get('/welcome', function () {
    return view('welcome');
})->name('welcome');

ref: https://pestphp.com/docs/higher-order-testing

i run php artisan test --parallel --group=my

route('welcome') prevented the Test start to run and throw an error

here the ->group('my') is for the whole test file

<?php

uses()->group('my');

test('welcome page is ok', function () {
    $this
        ->get('/welcome')
        ->assertOk();
});

test('welcome route is ok')
    ->get(route('welcome')) // <--- ERROR  Target class [url] does not exist.
    ->assertOk();

when i change to static path, all Test passed

test('welcome route is ok')
    ->get('/welcome')
    ->assertOk();

so how can use Laravel build-in helpers in the Pest Test?

0 likes
2 replies
nexxai's avatar

Have you installed the pestphp/pest-plugin-laravel package?

newbie360's avatar

@nexxai

https://jetstream.laravel.com/3.x/installation.html

Yes, with the command php artisan jetstream:install livewire --pest

pestphp/pest-plugin-laravel is default installed

so i guess is Pest higher-order-testing not allow use like this way

test('welcome route is ok')
    ->get(route('welcome'))
    ->assertOk();

but it work within a closure

test('welcome route is ok', function () {
    $this
        ->get(route('welcome'))
        ->assertOk();
});

Please or to participate in this conversation.