ct2000
2 years ago
421
13
Testing

Dusk problem: DatabaseTransactions

Posted 2 years ago by ct2000

See code below - works if I exclude the use DatabaseTransactions line, fails otherwise - the user doesn't seem to exist.

<?php

namespace Tests\Browser;


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


class LoginTest extends DuskTestCase
{
     use DatabaseTransactions;
    /**
     * Test login
     *
     * @return void
     */
    public function testLogin()
    {
        $user = factory(User::class)->create([
            'email' => '[email protected]',
            'password' => bcrypt('12345Hello!')
        ]);

        $this->browse(function ($browser) use ($user) {
            $browser->visit('/login')
                    ->type('email', $user->email)
                    ->type('password', '12345Hello!')
                    ->press('Login')
                    ->assertPathIs('/home');
        });
        
    }
}

Please sign in or create an account to participate in this conversation.