0

I've been trying to disable exception handling in my test so I can see the errors, but it's not working even if I intentionally break the code.

I'm just getting this generic response and it's not helping much.

Invalid JSON was returned from the route.

I've tried all solutions I can find online, but none of them is working.

I tried adding $this->disableExceptionHandling() at the top of the test method, it didn't work. I also tried the tutorial from Adam Wathan, (https://gist.github.com/adamwathan/125847c7e3f16b88fa33a9f8b42333da) that didn't work also.

I've even tried editing the Handler.php file

public function render($request, Exception $exception)
{
    throw $exception;
    // return parent::render($request, $exception);
}

It's still now working.

Please how can I fix this.

Any help would be appreciated.

Thanks.

Daniel
  • 67
  • 1
  • 7

2 Answers2

0

You can use this code in report method of handler.php

if (env('APP_ENV') === 'testing') {
    throw $exception;
}
Mohammad.Kaab
  • 1,025
  • 7
  • 20
0

Since Laravel 8 ( I think ) you can add the $this->withoutExceptionHandling() method to your tests and the exception will not get caught by the framework's handler. So you can:

public function test_page()
{
    $this->withoutExceptionHandling();
    $this->get('/');
    $this->assertSuccessful();
}

You could chain these all together if you wanted to.

See the docs here.

damask
  • 529
  • 4
  • 17