mardi 16 octobre 2018

Expected errors in Laravel Dusk

I'm new to using Laravel Dusk (running Laravel 5.7) and cannot find a way to test for an expected error. When I run the following test.

I get the following:

There was 1 error:

1) Tests\Browser\RegistrationTest::test_user_cannot_register_with_duplicate_email Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: users.email (SQL: insert into "users" ("name", "email", "password", "updated_at", "created_a t") values (Eoj, joe@example.com, 654321, 2018-10-16 20:35:09, 2018-10-16 20:35:09))

Caused by PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: users.email

ERRORS! Tests: 4, Assertions: 5, Errors: 1.

public function test_user_cannot_register_with_duplicate_email()
{
    User::create([
        'name' => 'Eoj',
        'email' => 'joe@example.com',
        'password' => '654321'

    ]);

    $this->browse(function ($browser) {
        $browser->visit('/') //Go to the homepage
        ->clickLink('Register') //Click the Register link
        ->assertSee('Register') //Make sure the phrase in the argument is on the page
        //Fill the form with these values
        ->value('#name', 'Joe')
            ->value('#email', 'joe@example.com')
            ->value('#password', '123456')
            ->value('#password-confirm', '123456')
            ->click('button[type="submit"]') //Click the submit button on the page
            ->assertPathIs('/register') //Make sure you are still on the register page
            //Make sure you see the phrase in the argument
            ->assertSee("The email has already been taken");
    });

}

Obviously I was expecting an error - but can't work out how to tell dusk this.



via Chebli Mohamed

1 commentaire:

  1. Get custom Laravel development services from a leading Laravel Development Company based in India & USA to build modern and robust solutions. Contact us for Information for Pricing: +91-9806724185 or Contact@expresstechsoftwares.com

    RépondreSupprimer