sinnbeck/laravel-dom-assertions
Extra DOM assertion helpers for Laravel HTTP tests. Assert elements, text, forms, selects, and datalists with more precision than assertSee/SeeText. Works with Livewire and Blade views/components; includes quick existence checks and a method reference.
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 | Parsing HTML in tests adds ~10–30ms per assertion (benchmark in CI). Mitigate by: |
--parallel).
| Maintenance Debt | Package is actively maintained (releases every 6 months). Risk of abandonment is 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. |find()/each() methods are critical for dynamic content.assertThat)? Steepness of learning curve is low to moderate.assertElementHasClass())? Overlap may require refactoring.assertFormExists()/findSelect()).x-data attributes for Alpine.js).| Step | Action | Effort | Risk |
|---|---|---|---|
| 1. Evaluation | Run existing tests with the package installed (dev dependency). | 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 (ensure no performance regression). | 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()).How can I help you explore Laravel packages today?