6

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?

5
  • did you try returning view return view('YourView'); Commented Oct 4, 2018 at 11:54
  • @MeeraTank am running feature tests not coding the actual features Commented Oct 4, 2018 at 12:52
  • @GEOFFREYMWANGI <contact-form></contact-form> doesn't seem like a valid html markup for me. So validating against it seems like bad practice. Proof me if I'm wrong.... Commented Oct 8, 2018 at 23:28
  • 2
    @Bart I believe the op is using a vue component. vuejs.org/v2/guide/components.html Commented Oct 8, 2018 at 23:39
  • @adam thanks for pointing that out. I'm not into Vue so much... But on the other hand, is Dusk capable of handling all the Vue markups? Commented Oct 8, 2018 at 23:49

2 Answers 2

9
+25

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 because assertSourceHas will look at the unrendered html. <contact-form> will no longer look like that after being rendered by Vue / react / angular / ... which is probably key in this question.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.