PHPackages                             mikerogne/laravel-tag-assertions - 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. mikerogne/laravel-tag-assertions

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

mikerogne/laravel-tag-assertions
================================

Adds useful tag assertions to Laravel's TestResponse class.

2.0.2(5y ago)01.1k1[3 issues](https://github.com/mikerogne/laravel-tag-assertions/issues)[3 PRs](https://github.com/mikerogne/laravel-tag-assertions/pulls)MITPHP

Since Dec 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mikerogne/laravel-tag-assertions)[ Packagist](https://packagist.org/packages/mikerogne/laravel-tag-assertions)[ RSS](/packages/mikerogne-laravel-tag-assertions/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

Laravel Tag Assertions
======================

[](#laravel-tag-assertions)

[Laravel](https://laravel.com/) ships with a number of awesome features, but one of my favorites is how easy it makes [testing your application](https://laravel.com/docs/master/testing).

Laravel Tag Assertions aims to make the incredible [HTTP tests](https://laravel.com/docs/master/http-tests) functionality that Laravel offers even more powerful by adding useful assertions for HTML tags.

### Motivations

[](#motivations)

Frequently I've wanted to assert a response contains certain elements (ie: Vue component with certain props), but didn't want newlines and other whitespace to matter. Using methods like `$response->assertSee(...)` is not ideal for this particular use-case. Laravel Dusk wasn't a desirable option either because it can be slow and sometimes fragile.

Installation
============

[](#installation)

```
composer require --dev mikerogne/laravel-tag-assertions

```

Once installed, your TestResponse instances now have access to new assertions. See below for usage &amp; examples.

Usage
=====

[](#usage)

### TestResponse::assertSeeTag(string $selector, array $attributes)

[](#testresponseassertseetagstring-selector-array-attributes)

**$selector** is the name of a tag you want to match. You can get as specific as you want. **$attributes** is either an array of attributes that the tag must have.

SimpleMore Specificbuttonbutton.btn.btn-defaultaa\[role=tab\]### TestResponse::assertSeeTag(string $selector, $callback)

[](#testresponseassertseetagstring-selector-callback)

If you specify a callback, three parameters will be passed to it:

1. **$tag**: This is the name of the tag itself, ie: `button` or `a`.
2. **$attributes**: This is an array of attributes for the tag, ie: `["class" => "btn btn-default"]`.
3. **$content**: This is a string representing the content (innerHtml). Whitespace is included.

### TestResponse::assertSeeTagContent(string $selector, string $content)

[](#testresponseassertseetagcontentstring-selector-string-content)

Sometimes we only care that a tag with specific content is on the page. A common use-case for this is a textarea field.

```
$response->assertSeeTagContent('textarea[name=about]', $user->about);

```

Examples
========

[](#examples)

Form Validation
---------------

[](#form-validation)

```

    Contrived Example

            First Name

            Last Name

            Email

            Register

```

```
