NPV's avatar
Level 1

How test /logout with dusk in Laravel 5.4

Update.

I understand. My bad. Login works through POST.

Hi!

I have Laravel 5.4 with standard auth system. I try do test for logout, but have error.

My test:

<?php

namespace Tests\Browser;

use App\User;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class LoginTest extends DuskTestCase
{
    use DatabaseMigrations;

    public function testLogout()
    {
        factory(User::class)->create([
            'email' => '[email protected]',
        ]);

        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit('/logout')
                ->assertGuest()
            ;
        });
    }
}

Error: There was 1 failure:

  1. Tests\Browser\LoginTest::testLogout The user is unexpectedly authenticated. Failed asserting that an array is empty.

/var/www/getinterlude/vendor/laravel/dusk/src/Concerns/InteractsWithAuthentication.php:80 /var/www/getinterlude/tests/Browser/LoginTest.php:42 /var/www/getinterlude/vendor/laravel/dusk/src/TestCase.php:88 /var/www/getinterlude/tests/Browser/LoginTest.php:44

I have tried many other options. But nothing is working. What is wrong?

Update.

I understand. My bad. Login works through POST.

0 likes
1 reply
dlucian's avatar

This worked for me:

$browser->visit('/logout')->logout()

No idea why it works.

LATER EDIT: probably because it logs out both remote accessed Chromedriver session and locally stored session.

Please or to participate in this conversation.