My Blog Posts

Laravel View Test Suite

Laravel View Test Suite

Laravel is a package for tests of views alone. 

class WelcomeTest extends TestCase
// First, add the `InteractsWithViews` trait to your test case class.
use InteractsWithViews;
public function testDisplaysLaravel()
// Then, get started with Mojito using the `assertView` method.

You can also use this package in HTTP tests:

$response = $this->get('/'); $response->assertStatus(200); $response->assertView()->contains('Laravel');

The API contains the following features during writing:

  • contains() - Verifies text given to view
  • has() - View  verifies the given selector
  • hasAttribute() - verifies that an item is the specified property
  • hasClass() - View verifythat it is the given class
  • hasLink() - View verifies the given connection

Several more examples of package methods:

$this->assertView('button')->contains('Click me');
// has
// hasAttribute
$this->assertView('button')-hasAttribute('attribute', 'value');
// hasClass
// hasLink

You can learn more about this package, get all the setup instructions, and view the source code on GitHub at nunomaduro/ laravel-mojito.

Share this article

Comments (0)