Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.5 & Vue.js Blade Testing

I have the following in my blade...

<div>
  <contact-form></contact-form>
</div>

I want to test to ensure that the Vue.js component is always mounted in my tests...

public function testRoute()
{
    $this->visit('/');
    //stuck here
}

Basically I'mm looking forward to testing that the blade has <contact-form>. How should I proceed?

like image 560
Geoff Avatar asked Oct 04 '18 09:10

Geoff


People also ask

Can I upgrade Laravel 5.8 to 8?

By default, Laravel 5.8 uses PHPUnit 7. However, you may optionally upgrade to PHPUnit 8, which requires PHP >= 7.2. In addition, please read through the entire list of changes in the PHPUnit 8 release announcement.

Does Laravel 8 require PHP 8?

Short response no, Laravel 8 requires PHP >= 7.3 From Server Requirements But, since you downgraded it is possible that some php packages require newer php versions no matter the version chosen for Laravel.

Which framework is best for Laravel?

MVC Architecture of Laravel Framework Laravel architecture is MVC-based, and this is something that makes Laravel the best PHP framework for website development. MVC architecture comes up with built-in functionalities that developers can use at their best while building your web app.


2 Answers

Use assertSee

Assert that the given string is contained within the response

$this
    ->visit('/')
    ->assertSee('<contact-form>')
    ->assertSee('</contact-form>');

See more laravel 5.5 testing assertions here

Or if you want to get deeper into client side browser testing look at Laravel Dusk, it has assertSourceHas method.

like image 95
Seva Kalashnikov Avatar answered Oct 24 '22 05:10

Seva Kalashnikov


You can use the call or get method from MakesHttpRequests.php trait to inspect the text:

// this returns \Illuminate\Foundation\Testing\TestResponse
$response = $this->get('/');
// use the TestResponse api
$response->assertSee($value);

Github source code reference: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php

https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Testing/TestResponse.php

like image 2
adam Avatar answered Oct 24 '22 06:10

adam