我们有一个操作来编辑重定向到同一页面的用户配置文件。 这里 seePageIs() 似乎没有等待新页面加载。
以下测试失败,因为在响应中找不到新用户名。当我们在测试后手动加载配置文件页面时,它已正确更新。
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);
}
编辑
$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);
});
也没有工作
最佳答案
问题是另一回事。 Laravel 正在按下按钮时重新加载页面。
在用户资料 View 中,我们使用Auth::user()
来显示信息。
当我做一个
Auth::setUser(Auth::user()->fresh());
在用户 Controller 中,它可以工作。
不是一个非常令人满意的解决方案 - 但它使原始问题变得清晰。
关于php - 如何在 Laravel 集成测试中等待页面重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39849082/