Laravel集成测试中如何等待页面重新加载 [英] How to wait for a page reload in Laravel integration testing

查看:137
本文介绍了Laravel集成测试中如何等待页面重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个操作来编辑用户个人资料,该个人资料会重定向到同一页面. 在这里,seePageIs()似乎并不等待新页面加载.

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

编辑

    $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 正在重新加载页面.

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

在用户个人资料视图中,我们使用Auth::user()来显示信息.

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

当我做

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

在用户控制器中有效.

这不是一个非常令人满意的解决方案-但这使最初的问题变得很清楚.

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

这篇关于Laravel集成测试中如何等待页面重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆