-1

I created a route that functions OK, but my tests are unable to detect it. Since the test is of type feature, all Laravel features should be included.

I recently updated both my Composer and npm packages, including Laravel itself. Could this be the root cause of the problem?

Manipulating the closure to return a view or use a specific controller, clearing the cache, and dump autoload haven't resolved the issue.

Pest.php

pest()->extend(Tests\TestCase::class)
    ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
    ->in('Feature', 'Unit');

RouteTest.php

test('example', function () {
    $response = $this->get('/');

    $response->assertStatus(200);
});

web.php

Route::get('/', function () {
   dd('Welcome!');
});

Test Error:

   FAILED  Tests\Feature\routes\ProjectRouteTest > example                                                                          
  Expected response status code [200] but received 404.
Failed asserting that 404 is identical to 200.

  at tests/Feature/routes/ProjectRouteTest.php:6
      2▕ 
      3▕ test('example', function () {
      4▕     $response = $this->get('/');
      5▕ 
  ➜   6▕     $response->assertStatus(200);
      7▕ });
      8▕ 


  Tests:    1 failed (1 assertions)
  Duration: 0.25s

Thank you in advance. I've been hung up on it for a while

6
  • Do you have setup something that would be able to receive and handle HTTP requests while you run your tests? Commented Apr 4 at 11:01
  • @Randommm Not precisely. However, I installed Laravel Breeze and upgraded dependencies. Commented Apr 4 at 11:09
  • @SajjadLabs is there a possibility you have global middlewares and one is throwing not found or 404? Commented Apr 4 at 11:29
  • @SajjadLabs the method dd(), while helpful for debug, doesn't return a 200 server response code. so the assert status on the response is correctly failing Commented Apr 4 at 13:59
  • Hi there, what web server are you using in this project? Commented Apr 7 at 1:08

1 Answer 1

0

Your routes may have been cached, so you should execute :

php artisan route:clear

This should delete the previously optimized routes.

You could also delete bootstrap/cache contents to fully delete the cached bootstrap configurations.

Alternatively you could run the Artisan::call(‘route:list’) inside your test class and check the output to see if the route is correctly bootstrapped.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.