Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abkrim's avatar
Level 13

Testing Nova

I like test my dashboard app made with nova.

I'm looking form examples in internet, but only see a example for use Spatie\Permission but I don't need this package.

My test code fail

/** @test */
    function super_admin_has_ui_access()
    {
        $user = factory(User::class)->create(['is_super_admin' => true]);

        $response = $this->actingAs($user)
            ->get('/nova/resources/users/1');


        $response->assertStatus(200);
    }

Also if test only dashdoard

$response = $this->actingAs($user)
            ->withSession(['foo' => 'bar'])
            ->get('/nova/dashboards/main');

error

1) Tests\Feature\NovaAccessTest::super_admin_has_ui_access
Expected status code 200 but received 403.
Failed asserting that false is true.

/home/abkrim/Sites/albarid/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:185
/home/abkrim/Sites/albarid/tests/Feature/NovaAccessTest.php:20

Any ideas?

0 likes
4 replies
manelgavalda's avatar

I think it's the same problem here: https://laracasts.com/discuss/channels/nova/laravel-nova-testing-with-phpunit

As @francoboy7 says, it's a problem with the testing environment and the nova gate permissons.

His solution, change the NovaServiceProvider.php:

protected function gate()  
{  
     Gate::define('viewNova', function ($user) {  
      return true;  
     });
 }

I suggest you to actually see his post and see for yourself if this solution works for you.

1 like

Please or to participate in this conversation.