How to wait for page reload while testing Laravel integration

We have an action to edit the user profile that is redirected to the same page. Here seePageIs () does not seem to be waiting for a new page to load.

The following test fails because the new username was not found in the response. When we load the profile page manually after the test, it was correctly updated.

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); } 

change

  $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 does not work

+5
php testing laravel
source share
1 answer

The problem was different. Laravel reloads the page when a button is clicked.

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

When i do

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

in the user controller, it works.

Not a very satisfactory solution - but this makes the original question clear.

0
source share

All Articles