Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

nshiro
Copy link
Contributor

@nshiro nshiro commented Dec 12, 2022

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