PHPackages                             savvywombat/laravel-assert-selector-contains - 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. savvywombat/laravel-assert-selector-contains

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

savvywombat/laravel-assert-selector-contains
============================================

Targeted content assertions using CSS selector expressions

1.3.1(2y ago)38.7k2MITPHPPHP ^8.1

Since Sep 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/SavvyWombat/laravel-assert-selector-contains)[ Packagist](https://packagist.org/packages/savvywombat/laravel-assert-selector-contains)[ Docs](https://github.com/SavvyWombat/laravel-assert-selector-contains)[ RSS](/packages/savvywombat-laravel-assert-selector-contains/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

Laravel AssertSelectorContains
==============================

[](#laravel-assertselectorcontains)

[![Latest Version on Packagist](https://camo.githubusercontent.com/35666d48ae7a7bca1733a979252242ab6662a693deb851966622fa6fae60e8f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361767679776f6d6261742f6c61726176656c2d6173736572742d73656c6563746f722d636f6e7461696e732e737667)](https://packagist.org/packages/savvywombat/laravel-assert-selector-contains)[![Supported PHP Version](https://camo.githubusercontent.com/f09a39b2de610a41d118695c4b2e85a5f7ab8a0955966d58c460bca11170da35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7361767679776f6d6261742f6c61726176656c2d6173736572742d73656c6563746f722d636f6e7461696e733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f09a39b2de610a41d118695c4b2e85a5f7ab8a0955966d58c460bca11170da35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7361767679776f6d6261742f6c61726176656c2d6173736572742d73656c6563746f722d636f6e7461696e733f7374796c653d666c61742d737175617265)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![Build](https://camo.githubusercontent.com/c64a7c88dd3b53dea3689e74c90cf83506696c2cfba147e1581f5ed0ae7048fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f5361767679576f6d6261742f6c61726176656c2d6173736572742d73656c6563746f722d636f6e7461696e732f746573742e796d6c3f6272616e63683d6d61696e)](https://github.com/SavvyWombat/laravel-assert-selector-contains/actions)[![Code Coverage](https://camo.githubusercontent.com/312e07464b5ee526e092859876d06a3cc07f72dec5be42664b5d4093fe3b2170/68747470733a2f2f636f6465636f762e696f2f67682f5361767679576f6d6261742f6c61726176656c2d6173736572742d73656c6563746f722d636f6e7461696e732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/SavvyWombat/laravel-assert-selector-contains)

Targeted content assertions using CSS selector expressions.

Laravel's built-in `assertSee` is useful, but has some limitations:

1. It makes a string match against the whole document, and could produce false positives.
2. It is hard to assert if specific items have been correctly set (page titles, input labels, etc)
3. When the assertion fails, it outputs the whole HTML document to the console.

This package provides a collection of additional assertions available on Laravel's `TestResponse` to help target specific elements/attributes and improve message on failure.

```
assertSelectorExists($selector)
assertSelectorDoesNotExist($selector)

assertSelectorContains($selector, $value)
assertSelectorDoesNotContain($selector, $value)

assertSelectorAttributeExists($selector, $attribute)
assertSelectorAttributeDoesNotExist($selector, $attribute)

assertSelectorAttributeEquals($selector, $attribute, $value)
assertSelectorAttributeDoesNotEqual($selector, $attribute, $value)

assertSelectorAttributeContains($selector, $attribute, $value)
assertSelectorAttributeDoesNotContain($selector, $attribute, $value)

```

So, if you want to make sure that you are correctly setting the document title:

`$response->assertSelectorContains('title', 'Welcome');`

If you want to assert that a label has been set for a specific form input:

`$response->assertSelectorExists('label[for=input-id]');`

Or if a specific input has been set with the correct initial value:

`$response->assertSelectorAttributeEquals('input[name=display_name]', 'value', 'SavvyWombat');`

Installation
------------

[](#installation)

This package is available using [Composer](https://getcomposer.org/).

`composer require --dev savvywombat/laravel-assert-selector-contains`

Usage
-----

[](#usage)

```
namespace Tests\Feature;

use SavvyWombat\LaravelAssertSelectorContains\AssertsWithSelectors;
use Tests\TestCase;

class ExampleTest extends TestCase
{
  use AssertsWithSelectors;

  public function testDocumentTitleIsCorrect(): void
  {
    $response = $this->get('/');

    $response->assertSelectorContains('title', 'Welcome');
  }
}
```

Credit
------

[](#credit)

This package was inspired by a blog post from Liam Hammett:

[Laravel Testing CSS Selector Assertion Macros](https://liamhammett.com/laravel-testing-css-selector-assertion-macros-D9o0YAQJ)

Support
-------

[](#support)

Please report issues using the [GitHub issue tracker](https://github.com/SavvyWombat/LaravelAssertSelectorContains/issues). You are also welcome to fork the repository and submit a pull request.

Licence
-------

[](#licence)

This package is licensed under [The MIT License (MIT)](https://github.com/SavvyWombat/LaravelAssertSelectorContains/blob/master/LICENSE).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

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 ~108 days

Total

5

Last Release

902d ago

PHP version history (2 changes)1.0.0PHP ^8.0

1.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/949f4b63b47c6f037d6ddd22ad3c34e67950655eb51a31d2b1f1205eac7005d7?d=identicon)[SavvyWombat](/maintainers/SavvyWombat)

---

Top Contributors

[![horuskol](https://avatars.githubusercontent.com/u/290549?v=4)](https://github.com/horuskol "horuskol (18 commits)")[![samlev](https://avatars.githubusercontent.com/u/462466?v=4)](https://github.com/samlev "samlev (3 commits)")

---

Tags

testlaravelsavvywombatsavvy wombat

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/savvywombat-laravel-assert-selector-contains/health.svg)

```
[![Health](https://phpackages.com/badges/savvywombat-laravel-assert-selector-contains/health.svg)](https://phpackages.com/packages/savvywombat-laravel-assert-selector-contains)
```

PHPackages © 2026

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