Laravel 7: assertSee() and html entities
Asked Answered
B

2

1

In my test, I use assertSee().

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

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

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

How can I do it?

Behnken answered 24/9, 2020 at 0:2 Comment(0)
B
11

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

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

Just set it to false.

Documentation says:

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

Behnken answered 24/9, 2020 at 0:2 Comment(0)
G
0

I faced the same problem. So I had to look everywhere. For me assertSee did not help. Then I looked at laravel documentation. in my case I had to look values within table.

According to laravel documentation you can use

$value = $browser->text('selectors'); //css selectors here
$this->assertSame('Expected HTML data', $value);
Grandma answered 25/8 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.