Skip to content

[9.x] Improve assertSeeText and assertDontSeeText test methods - #45274

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
nshiro:improve_assert_see_text
Dec 12, 2022
Merged

[9.x] Improve assertSeeText and assertDontSeeText test methods#45274
taylorotwell merged 1 commit into
laravel:9.xfrom
nshiro:improve_assert_see_text

Conversation

@nshiro

@nshiro nshiro commented Dec 12, 2022

Copy link
Copy Markdown
Contributor

When you use assertSee test method and fail the test, you get a message like below.

  ' contains "Hello, Taylor.".

  at tests/Feature/ExampleTest.php:20
     16▕     {
     17▕         $response = $this->get('/');
     18▕
     19▕         $response->assertStatus(200)
  ➜  20▕             ->assertSee('Hello, Taylor.');

This is ok.
But meanwhile if you use assertSeeText and fail the test, you get a message like below.

  ' contains "Hello, Taylor.".

  at vendor/laravel/framework/src/Illuminate/Support/helpers.php:306
    302▕         if (is_null($callback)) {
    303▕             return new HigherOrderTapProxy($value);
    304▕         }
    305▕
  ➜ 306▕         $callback($value);
    307▕
    308▕         return $value;
    309▕     }
    310▕ }

This is not so helpful or just confusing.
To solve this, we can just forget about nice helper function tap and use the old-fashioned way.
By doing so, we can get the same error message as assertSee.
The same applies to assertDontSeeText.

@taylorotwell
taylorotwell merged commit 26c476d into laravel:9.x Dec 12, 2022
@nshiro
nshiro deleted the improve_assert_see_text branch December 12, 2022 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants