- How do I install this package for Laravel 10+ with PHP 8.1?
- Run `composer require sinnbeck/laravel-dom-assertions --dev` in your project. The package is a dev dependency and won’t affect production. Ensure your `composer.json` specifies Laravel 10+ and PHP 8.1+ in requirements.
- Can I use this package with Livewire components?
- Yes, the package includes Livewire-specific assertions like `assertFormExists()` and `findSelect()` to test dynamic content. Use `assertElementExists()` on Livewire responses, and chain methods like `find()` to traverse nested elements.
- What’s the difference between `assertElementExists()` and Laravel’s `assertSee()`?
- `assertElementExists()` provides granular DOM assertions (e.g., checking attributes, forms, or selects) with fluent chaining, while `assertSee()` only verifies text presence. This package supports complex selectors, ARIA attributes, and hierarchical traversal.
- Does this package work with Alpine.js or Inertia.js?
- Yes, it works with Alpine.js by asserting dynamic attributes (e.g., `x-data` or `x-bind`) and Inertia.js by validating page structure. Use `find()` to locate elements with Alpine reactivity markers or Inertia’s page IDs.
- How do I test forms with this package?
- Use `assertFormExists()` to verify form presence, then chain methods like `findInput()` or `findSelect()` to validate fields. Example: `assertFormExists()->findInput('email')->assertHasValue('test@example.com').`
- Will this package slow down my test suite?
- Minimal overhead—DOM parsing adds ~10–30ms per assertion. Mitigate by limiting assertions to critical paths or using parallel test runners like PestPHP’s `--parallel`. Benchmark in CI to ensure no regression.
- Can I use this with Laravel 9 or PHP 8.0?
- Yes, install version 2.x with `composer require sinnbeck/laravel-dom-assertions:^2.0 --dev`. Check the [README](https://github.com/sinnbeck/laravel-dom-assertions) for version-specific features.
- How do I handle flaky tests with dynamic content (e.g., Livewire)?
- Use `waitFor()` or `refresh()` methods to retry assertions on dynamic content. Example: `assertElementExists()->waitFor(2)->find('#dynamic-element')`. Avoid timing-based waits; prefer explicit retries.
- Are there alternatives for complex JavaScript testing?
- For heavy JavaScript (e.g., SPAs), use Playwright or Cypress instead. This package focuses on server-rendered DOM assertions—ideal for Laravel’s Blade/Livewire but not full frontend testing.
- How do I assert ARIA attributes or accessibility features?
- Use `assertElementExists()->assertHasAttribute('aria-label', 'Submit')` or `assertHasRole('button')`. The package supports ARIA roles, labels, and semantic HTML validation for accessibility testing.