Laravel Mojito is a lightweight package for testing Laravel views in isolation. Here’s an example of basic usage from the readme:
1class WelcomeTest extends TestCase 2{ 3 // First, add the `InteractsWithViews` trait to your test case class. 4 use InteractsWithViews; 5 6 public function testDisplaysLaravel() 7 { 8 // Then, get started with Mojito using the `assertView` method. 9 $this->assertView('welcome')->contains('Laravel');10 }11}You can also use this package in HTTP tests:
1$response = $this->get('/');2 3$response->assertStatus(200);4 5$response->assertView()->contains('Laravel');The API includes the following features at the time of writing:
contains()– assert the view has the given texthas()– assert the view has the given selectorhasAttribute()– assert an element has the given attribute valuehasClass()– assert the view has an element with the given classhasLink()– assert the view has an element with the given link
Here’s some more examples of the package methods:
1// contains 2$this->assertView('button')->contains('Click me'); 3 4// has 5$this->assertView('welcome')->in('body')->has('.content') 6 7// hasAttribute 8$this->assertView('button')->hasAttribute('attribute', 'value'); 9 10// hasClass11$this->assertView('button')->hasClass('btn');12 13// hasLink14$this->assertView('button')->hasLink(route('welcome'));You can learn more about this package, get full installation instructions, and view the source code on GitHub at nunomaduro/laravel-mojito.
0 comments:
Post a Comment
Thanks