Laravel 7:assertSee()和html实体 [英] Laravel 7: assertSee() and html entities

查看:49
本文介绍了Laravel 7:assertSee()和html实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试中,我使用assertSee().​​

In my test, I use assertSee().

    $message = '<h1>Header</h1>';
    $response = $this->get($url);
    $response->assertStatus(200);
    $response->assertSee($message);

问题是,当 $ message 包含html实体时,则断言为假.

The problem is that when the $message contains html entities then the assertion gets false.

我知道有一个 e()助手可以在$ message中转换html实体,但是现在我需要相反的操作.

I know there is an e() helper to do convert html entities in $message but now I need the opposite.

我该怎么办?

推荐答案

-> assertSee(...)是

->assertSee(...) is changed in Laravel 7, now it has a second parameter

$response->assertSee($value, $escaped = true);

只需将其设置为 false .

文档说:

该断言将自动转义给定的字符串,除非您传递第二个参数false:

This assertion will automatically escape the given string unless you pass a second argument of false:

这篇关于Laravel 7:assertSee()和html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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