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.
assertSee/assertDontSee. It aligns with behavior-driven testing (BDD) and UI regression testing needs, particularly for:
assertElementExists() → find() → each()) mirrors jQuery-like chaining, reducing boilerplate for hierarchical DOM traversal.get(), actingAs()) and Livewire testing utilities.--dev), avoiding production bloat.Http::fake()).| Risk Area | Mitigation Strategy |
|---|---|
| Test Flakiness | DOM assertions are deterministic (unlike timing-based checks), but dynamic content (e.g., Livewire) may require waitFor() or refresh() strategies. |
| Performance Overhead | v3.3.0 includes assertion speed improvements. Prior estimate of ~10–30ms per assertion should be re-benchmarked after upgrade; expected overhead is lower, but actual impact depends on suite size and DOM complexity. Mitigate by limiting assertions to critical paths and using parallel test suites (PestPHP’s --parallel). |
| Maintenance Debt | Package is actively maintained (v3.3.0 published 2026-06-16). Risk of abandonment remains low. |
| False Positives | Whitespace normalization (normalize_whitespace) can mask real UI issues if misconfigured. |
| Selector Complexity | Overly specific CSS selectors (e.g., div:nth-of-type(3) > span) may break with UI changes. Solution: Use data-test attributes for stability. |
| Upgrade Risk | v3.3.0 appears to be a minor performance/CI release with no breaking changes called out. Standard mitigation: upgrade in a branch, run full test suite, and compare CI runtime before/after. |
find()/each() methods are critical for dynamic content.assertThat)? Learning curve is low to moderate.assertElementHasClass())? Overlap may require refactoring.assertFormExists()/findSelect()).x-data attributes for Alpine.js).| Step | Action | Effort | Risk |
|---|---|---|---|
| 1. Upgrade / Evaluation | Upgrade dev dependency to v3.3.0 and run existing test suite. Re-benchmark assertion overhead. | Low | Low |
| 2. Pilot Test Suite | Replace 5–10% of flaky/verbose tests with DOM assertions (e.g., form validation). | Medium | Medium |
| 3. Standardize Selectors | Enforce data-test attributes (e.g., <button data-test="submit-btn">) for stability. |
Medium | Low |
| 4. CI Integration | Add to test suite in CI and compare runtime before/after v3.3.0 performance improvements. | Low | Low |
| 5. Full Adoption | Migrate all UI-related tests (e.g., assertSee() → assertElementContainsText()). |
High | Medium |
laravel/html or custom assertions).assertSee('Submit') → assertElementContainsText('#submit-btn', 'Submit').assertFormExists() for forms, findSelect() for dropdowns.data-test-* attributes to critical elements (e.g., buttons, inputs).waitFor() or refresh() before assertions.UserProfileTest::testFormSubmission()).sleep(1)) with deterministic DOM assertions.assertFormExists('#login-form')->hasCSRF() is clearer than assertSee('_token').data-test-*).data-test-*, tests may break with minor UI tweaks.normalize_whitespace setting may need tuning over time.x-data to be {foo: 1}, got {foo: 2}").find() vs. each()).data-test-* attributes.waitFor()/refresh().How can I help you explore Laravel packages today?