Download the PHP package mikerogne/laravel-tag-assertions without Composer
On this page you can find all versions of the php package mikerogne/laravel-tag-assertions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mikerogne/laravel-tag-assertions
More information about mikerogne/laravel-tag-assertions
Files in mikerogne/laravel-tag-assertions
Package laravel-tag-assertions
Short Description Adds useful tag assertions to Laravel's TestResponse class.
License MIT
Informations about the package laravel-tag-assertions
Laravel Tag Assertions
Laravel ships with a number of awesome features, but one of my favorites is how easy it makes testing your application.
Laravel Tag Assertions aims to make the incredible HTTP tests functionality that Laravel offers even more powerful by adding useful assertions for HTML tags.
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
Once installed, your TestResponse instances now have access to new assertions. See below for usage & examples.
Usage
TestResponse::assertSeeTag(string $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.
Simple | More Specific |
---|---|
button | button.btn.btn-default |
a | a[role=tab] |
TestResponse::assertSeeTag(string $selector, $callback)
If you specify a callback, three parameters will be passed to it:
- $tag: This is the name of the tag itself, ie:
button
ora
. - $attributes: This is an array of attributes for the tag, ie:
["class" => "btn btn-default"]
. - $content: This is a string representing the content (innerHtml). Whitespace is included.
TestResponse::assertSeeTagContent(string $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.
Examples
Form Validation
Vue Component
Callback Example
License
This code is open-sourced software licensed under the MIT license.