Download the PHP package soyhuce/laravel-embuscade without Composer
On this page you can find all versions of the php package soyhuce/laravel-embuscade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-embuscade
Test Laravel views in isolation
Inspired by nunomaduro/laravel-mojito
Test your Laravel views in isolation, interacting directly with the HTML.
Installation
You can install the package via composer:
Usage
Accessing view expectations
The most basic way to access the ViewExpect is to create it with an HTML string :
As this is not the most convenient way, you can create the ViewExpect from various objects:
If you use Livewire, you can also create a ViewExpect from a Livewire test component:
Navigating the view
Once the ViewExpect is created, you can navigate the view using the following methods:
$cssSelector
must be any valid CSS selector, like .class
, #id
, tag
, tag.class
, tag#id
, tag[attr=value]
, etc.
Note : Some pseudo-classes and pseudo-elements are not supported, like
:hover
,:before
,:after
,:has
, etc.
Embuscade selectors
You can also use Embuscade selectors to navigate the view as navigating CSS selectors can be cumbersome:
You can also use the @embuscade
directive to generate Embuscade selectors in your blade views:
The data-embuscade
attribute will be added to the element, only on testing environment or is debug mode is enabled.
Note : Because @embuscade is not really a blade directive, it requires use of single quotes
'
to work and won't have access to execution context.@embuscade("login-button")
will not work.will not work either.
You can customize the HTML attribute Embuscade will use for the selectors using selectorHtmlAttribute
method:
In production
If you run in production without dev-dependencies installed, you will need an extra setup in order to remove @embuscade
directives from your views.
In your AppServiceProvider::boot
method, you can add the following code:
There won't be any overhead here as cached views won't contain any @embuscade
directive.
Note : if you run in production with your dev-dependencies installed, you should definitively consider removing them.
Expectations
Expectations on entire view
Some expectations will be applied to the entire view:
Expectations on current element
Other expectation will only look at current root:
Some helpers are also available for you:
Negating expectation
You can negate any expectation by calling not
before the expectation:
The negation will only apply to the next expectation.
Navigating and expectations on elements
You can navigate and apply expectations on elements in a single chain, in order to not loose focus on the current element: Given the following HTML:
you can test it with the following code:
Every selection method will allow you to pass a closure that will receive a new ViewExpect, focused on the selected element.
Customization
The ViewExpect
class is macroable, so you can add your own expectations:
Debugging
You can dump the current state of the ViewExpect using the dump
or dd
methods:
It will dump the current HTML node.
WTF is Embuscade ?
Embuscade is a French word meaning ambush. It makes reference to the original package name, Laravel Mojito, as "une embuscade" is also a famous local cocktail from Caen.
Each bar has its own recipe, but it could be something like:
- 20 cl of blond beer
- 12 cl of white wine
- 8 cl of calvados (cider brandy, 40% alcohol)
- 4 cl of blackcurrant syrup
- 4 cl of lemon syrup
Easy to drink but quite strong, be careful not to fall into the ambush!
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Bastien Philippe
- Nuno Maduro for the inspiration with laravel-mojito
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-embuscade with dependencies
ext-dom Version *
illuminate/contracts Version ^12.0
illuminate/testing Version ^12.0
spatie/laravel-package-tools Version ^1.16
symfony/css-selector Version ^7.2
symfony/dom-crawler Version ^7.2