PHPackages                             nunomaduro/laravel-mojito - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. nunomaduro/laravel-mojito

ActiveLibrary[Testing &amp; Quality](/categories/testing)

nunomaduro/laravel-mojito
=========================

A lightweight package for testing Laravel views.

v0.2.10(4y ago)368435.5k↓15%16[1 issues](https://github.com/nunomaduro/laravel-mojito/issues)[1 PRs](https://github.com/nunomaduro/laravel-mojito/pulls)10MITPHPPHP ^7.2.5|^8.0

Since Feb 16Pushed 2y ago7 watchersCompare

[ Source](https://github.com/nunomaduro/laravel-mojito)[ Packagist](https://packagist.org/packages/nunomaduro/laravel-mojito)[ RSS](/packages/nunomaduro-laravel-mojito/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (13)Used By (10)

 [![Mojito example](https://raw.githubusercontent.com/nunomaduro/laravel-mojito/master/docs/example.png)](https://raw.githubusercontent.com/nunomaduro/laravel-mojito/master/docs/example.png)

 [![Build Status](https://camo.githubusercontent.com/c38a28d6bbab023f2935845373d07032d36b71b90ad29053571813f25af9d33f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e756e6f6d616475726f2f6c61726176656c2d6d6f6a69746f2f6d61737465722e737667)](https://travis-ci.org/nunomaduro/laravel-mojito) [![Total Downloads](https://camo.githubusercontent.com/443c44dd02b26894daa3edd98867efa1ba7b3ce3141474f0e752b330c6630543/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6c61726176656c2d6d6f6a69746f2f642f746f74616c2e737667)](https://packagist.org/packages/nunomaduro/laravel-mojito) [![Latest Version](https://camo.githubusercontent.com/79d621794452f35629d6d19355a9c155fe4646723a4139ea4f5c8f0999749f3d/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6c61726176656c2d6d6f6a69746f2f762f737461626c652e737667)](https://packagist.org/packages/nunomaduro/laravel-mojito) [![License](https://camo.githubusercontent.com/616f522d8d4b8579829ae715044230b50df25deb873cd5728e5bfb46ddd8e701/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6c61726176656c2d6d6f6a69746f2f6c6963656e73652e737667)](https://packagist.org/packages/nunomaduro/laravel-mojito)

About Mojito
------------

[](#about-mojito)

Mojito was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a lightweight package for testing Laravel views in isolation.

Installation &amp; Usage
------------------------

[](#installation--usage)

> **Requires [PHP 8.0+](https://php.net/releases/)**

Require Mojito using [Composer](https://getcomposer.org):

```
composer require nunomaduro/laravel-mojito --dev
```

How to use:

```
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.
        $this->assertView('welcome')->contains('Laravel');
    }
}
```

Optionally, you can also perform view testing from your HTTP Tests:

```
class WelcomeTest extends TestCase
{
    public function testDisplaysLaravel()
    {
        $response = $this->get('/');

        $response->assertStatus(200);

        $response->assertView()->contains('Laravel');
    }
}
```

### `contains`

[](#contains)

Asserts that the view contains the given text.

```
$this->assertView('button')->contains('Click me');
$this->assertView('button', ['submitText' => 'Cancel'])->contains('Cancel');

$this->assertView('welcome')->in('title')->contains('Laravel');
$this->assertView('welcome')->in('.content')->contains('Nova');
```

### `empty`

[](#empty)

Asserts that the view has no text content.

*Note: empty html nodes are not considered in this check.*

```
$this->assertView('empty')->in('.empty-div')->empty();
```

### `first`

[](#first)

Filters the view and returns only the first element matching the selector.

```
$this->assertView('welcome')->first('.links a')->contains('Docs');
```

### `has`

[](#has)

Asserts that the view has the given selector.

```
$this->assertView('button')->has('button');

$this->assertView('welcome')->has('head');
$this->assertView('welcome')->in('body')->has('.content');
```

### `hasAttribute`

[](#hasattribute)

Asserts that the view **root element** has the given attribute value.

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

$this->assertView('welcome')->hasAttribute('lang', 'en');
$this->assertView('welcome')->in('head')->first('meta')->hasAttribute('charset','utf-8');
```

### `hasClass`

[](#hasclass)

Asserts that the view has an element with the given class.

```
$this->assertView('button')->hasClass('btn');

$this->assertView('welcome')->in('.content')->at('div > p', 0)->hasClass('title');
```

### `hasLink`

[](#haslink)

Asserts that the view has an element with the given link.

```
$this->assertView('button')->hasLink(route('welcome'));

$this->assertView('welcome')->in('.links')->first('a')->hasLink('https://laravel.com/docs');
$this->assertView('welcome')->in('.links')->at('a', 6)->hasLink('https://vapor.laravel.com');
$this->assertView('welcome')->in('.links')->last('a')->hasLink('https://github.com/laravel/laravel');
```

### `in`

[](#in)

Filters the view and returns only the elements matching the selector.

```
$this->assertView('welcome')->in('.links a')->contains('Laracast');
```

### `last`

[](#last)

Filters the view and returns only the last element matching the selector.

```
$this->assertView('welcome')->last('.links a')->contains('GitHub');
```

### `hasMeta`

[](#hasmeta)

Asserts that the view has a given metatag in the head section.

```
$response->assertView()->hasMeta(['property' => 'og:title']);
$response->assertView()->hasMeta(['property' => 'og:title', 'content' => 'Laravel']);
```

### Macroable

[](#macroable)

Feel free to add your own macros to the `ViewAssertion::class`.

```
use NunoMaduro\LaravelMojito\ViewAssertion;

// Within a service provider:
ViewAssertion::macro('hasCharset', function (string $charset) {
    return $this->in('head')->first('meta')->hasAttribute('charset', $charset);
});

// In your tests:
$this->assertView('welcome')->hasCharset('utf-8');
```

Contributing
------------

[](#contributing)

Thank you for considering to contribute to Mojito. All the contribution guidelines are mentioned [here](CONTRIBUTING.md).

You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates &amp; detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro)

Support the development
-----------------------

[](#support-the-development)

**Do you like this project? Support it by donating**

- GitHub sponsors: [Donate](https://github.com/sponsors/nunomaduro)
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
- Patreon: [Donate](https://www.patreon.com/nunomaduro)

License
-------

[](#license)

Mojito is an open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~109 days

Total

12

Last Release

1586d ago

PHP version history (2 changes)v0.1.0PHP ^7.2

v0.2.6PHP ^7.2.5|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/86cfef5c1f5195df1a9db17a5f8ecb34455e1f0133a725de9acf7f2fb26ac6a1?d=identicon)[nunomaduro](/maintainers/nunomaduro)

---

Top Contributors

[![SimoTod](https://avatars.githubusercontent.com/u/8427737?v=4)](https://github.com/SimoTod "SimoTod (32 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (31 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (18 commits)")[![Abdullah-Hejazi](https://avatars.githubusercontent.com/u/46539561?v=4)](https://github.com/Abdullah-Hejazi "Abdullah-Hejazi (3 commits)")[![chaseconey](https://avatars.githubusercontent.com/u/1449463?v=4)](https://github.com/chaseconey "chaseconey (2 commits)")[![glennforrest](https://avatars.githubusercontent.com/u/12944411?v=4)](https://github.com/glennforrest "glennforrest (1 commits)")[![peterfox](https://avatars.githubusercontent.com/u/1716506?v=4)](https://github.com/peterfox "peterfox (1 commits)")[![amirsadeghi1](https://avatars.githubusercontent.com/u/26359326?v=4)](https://github.com/amirsadeghi1 "amirsadeghi1 (1 commits)")

---

Tags

phptestinglaravelpackage

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nunomaduro-laravel-mojito/health.svg)

```
[![Health](https://phpackages.com/badges/nunomaduro-laravel-mojito/health.svg)](https://phpackages.com/packages/nunomaduro-laravel-mojito)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laracasts/integrated

Simple, intuitive integration testing with PHPUnit.

479206.9k2](/packages/laracasts-integrated)[spatie/laravel-visit

Quickly visit any route of your Laravel app

15614.6k](/packages/spatie-laravel-visit)[juampi92/test-seo

Easy way to test your SEO

26341.0k](/packages/juampi92-test-seo)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

1484.6k3](/packages/calebdw-larastan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
