Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Dom Assertions

Laravel Dom Assertions Laravel Package

sinnbeck/laravel-dom-assertions

Extra DOM assertion helpers for Laravel HTTP tests, giving you finer control than assertSee and friends: assert on elements, forms, selects, datalists, and text, with quick existence checks and Livewire/Blade support.

View on GitHub
Deep Wiki
Context7

sinnbeck/laravel-dom-assertions adds powerful DOM-based assertion helpers to Laravel HTTP tests, giving you far more control than assertSee and friends when verifying rendered HTML. Chain CSS selectors to assert on elements, attributes, forms, selects, datalists, and text, making view tests precise and readable.

  • Element assertions via assertElementExists()/assertElement() with CSS selector support
  • Form, select, and datalist assertions for inputs, options, and values
  • Text assertions scoped to specific elements
  • Quick existence checks and Livewire/Blade component support
  • Includes Rector rules for easy upgrades
Frequently asked questions about Laravel Dom Assertions
How do I install sinnbeck/laravel-dom-assertions for Laravel HTTP tests?
Install it as a dev dependency with composer require sinnbeck/laravel-dom-assertions --dev. Version 3.x and above requires PHP 8.1+ and Laravel 10+, while projects on PHP 8.0 or Laravel 9 should install the 2.x line with composer require sinnbeck/laravel-dom-assertions:^2.0 --dev. No backend changes are needed; you only modify your HTTP tests to use the new assertion helpers.
Does laravel-dom-assertions support Laravel 9 or PHP 8.0?
Yes, but you must use version 2.x of the package. Version 3.x and newer requires PHP 8.1+ and Laravel 10+, so legacy stacks should pin to ^2.0. This backward-compatible release makes adoption easier for older Laravel applications.
What can laravel-dom-assertions do that assertSee and assertSeeText cannot?
assertSee and assertSeeText check whether a string appears in the raw response, while this package parses the HTML DOM and lets you assert on specific elements, attributes, forms, selects, and datalists. You can target nested structures with fluent closures such as assertElementExists followed by find and each. That gives you more precise UI validation for Blade, Livewire, and component-driven views.
Can I use laravel-dom-assertions with Livewire component tests?
Yes, the package works alongside Livewire testing utilities and is useful for validating dynamic server-rendered markup. For content that updates asynchronously, combine DOM assertions with Livewire's waitFor or refresh strategies where appropriate. The find and each methods help traverse dynamic component output without brittle text matching.
How do I assert that a form, select, or datalist exists in a Laravel test?
Use helpers such as assertFormExists, findSelect, and the datalist assertions on a Laravel test response. These methods let you verify form structure, select options, and datalist contents more precisely than plain text assertions. They are designed for HTTP tests and integrate with Laravel's existing get and actingAs helpers.
What are quick existence checks in sinnbeck/laravel-dom-assertions?
Quick existence checks are lightweight helpers like assertElementExists and its alias assertElement that confirm an element is present without writing a full traversal. The package also includes quick checks for other DOM structures such as forms and datalists. They reduce boilerplate when you only need to verify that a key UI element rendered.
Will DOM assertions make my Laravel test suite slower?
Parsing HTML in tests can add roughly 10 to 30ms per assertion in CI, depending on the response size and assertion complexity. Keep assertions focused on critical UI paths and run parallel test suites, such as PestPHP with --parallel, to offset the overhead. DOM assertions are deterministic, so they avoid timing-based flakiness common in browser tests.
Can laravel-dom-assertions replace Cypress or Playwright for UI testing?
No. It is an integration-only package for asserting on server-rendered HTML in Laravel HTTP tests, not a browser automation tool. It cannot exercise complex JavaScript, real browser events, or client-side rendering the way Cypress or Playwright can. Use it to complement browser tests by covering fast, deterministic DOM structure and content checks.
How do I avoid brittle DOM assertions in Laravel tests?
Prefer stable data-test attributes, such as a button with data-test set to submit-btn, instead of overly specific CSS selectors like div:nth-of-type(3) > span. Overly specific selectors break when layouts or component markup change, while data-test attributes survive refactors. Also be careful with whitespace normalization, since normalize_whitespace can hide real UI issues if misconfigured.
Is sinnbeck/laravel-dom-assertions actively maintained?
Yes, the package is actively maintained with releases roughly every six months, so the risk of abandonment is considered low. It is installed as a Composer dev dependency, which keeps it out of production deployments. Check the GitHub repository and Packagist for the latest version and Laravel compatibility badges.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings