Test Views with Laravel Mojito

Test Views with Laravel Mojito

Laravel Mojito is a lightweight package for testing Laravel views in isolation. Here’s an example of basic usage from the readme:

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('/');



The API includes the following features at the time of writing:

  • contains() – assert the view has the given text
  • has() – assert the view has the given selector
  • hasAttribute() – assert an element has the given attribute value
  • hasClass() – assert the view has an element with the given class
  • hasLink() – assert the view has an element with the given link

Here’s some more examples of the package methods:

// contains
$this->assertView('button')->contains('Click me');

// has

// hasAttribute
$this->assertView('button')->hasAttribute('attribute', 'value');

// hasClass

// hasLink

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

Filed in: News / packages
Laravel News Partners

Laravel Jobs

Senior Full-Time Laravel Developer (REMOTE)
Vue School
Senior Laravel Developer
Remote, USA & Canada Only
Backend Software Engineer
Remote, USA Only
Full Stack Laravel Developer (Full-time/Contract)
Remote or Columbus, OH
Backend PHP Developer


Join 31,000+ others and never miss out on new tips, tutorials, and more.