简体   繁体   中英

How to wait for a page reload in Laravel integration testing

We have a action to edit the user profile which redirects to the same page. Here seePageIs() does not seem to wait for the new page to load.

The following test fails, as the new user name is not found in the response. When we load the profile page manually after the test, it was updated properly.

public function testCanEditUserProfileAsConsumer()
{
    $this->loginConsumer();

    $this->visit('/user/profile');
    $firstName = $this->faker->firstname;
    $name = $this->faker->name;


    $this->within('#userEditForm', function() use ($firstName, $name) {
        $this->type($firstName, 'firstname');
        $this->type($name, 'surname');
        $this->press('Speichern');
    });

    // here: how to wait for page reload ?
    $this->seePageIs('/user/profile');
    $this->see($firstName);
    $this->see($name);
}

edit

    $this->within('#userEditForm', function() use ($firstName, $lastname) {
        $this->type($firstName, 'firstname');
        $this->type($lastname, 'surname');
        $this->press('Speichern')
            ->seePageIs('/user/profile')
            ->see($firstName)
            ->see($lastname);
    });

also not working

The problem was a different one. Laravel is reloading the page when pressing the button.

In the view of the user profile, we use Auth::user() to display information.

When I do a

    Auth::setUser(Auth::user()->fresh());

in the user controller, it works.

Not a very satisfying solution - but the it makes the original question clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM