- How do I install spatie/pest-plugin-snapshots in my Laravel project?
- Run `composer require spatie/pest-plugin-snapshots --dev` in your Laravel project. No additional Laravel-specific configuration is needed—it integrates seamlessly with Pest’s existing setup.
- Does this package work with Pest v3 and Laravel 10?
- Yes, the package explicitly supports Pest v2/v3 and Laravel 9/10+. The changelog confirms Pest v3 compatibility starting from version 2.2.0, so you’re covered for modern Laravel stacks.
- Can I use snapshot testing for Livewire or InertiaJS components?
- Absolutely. The package lets you test rendered Livewire or Inertia components directly with `expect($livewire->render())->toMatchSnapshot()` or similar assertions for JSON/API responses.
- How do I handle dynamic data like timestamps in snapshots?
- Use `assertMatchesJsonSnapshot()` with `ignoreKeys()` to exclude dynamic fields (e.g., timestamps). For example: `assertMatchesJsonSnapshot($response->json(), ignoreKeys: ['created_at'])`.
- Will snapshot tests slow down my CI/CD pipeline?
- Snapshot tests can add overhead, but they run efficiently in CI. Use the `--update-snapshots` flag sparingly (e.g., for intentional changes) and clean up unused snapshots with `.gitignore` or scripts.
- Can I customize where snapshots are stored?
- Yes, snapshots default to `tests/Snapshots/` but can be moved via the `SNAPSHOT_PATH` environment variable. This avoids conflicts with existing test structures.
- What if my team isn’t familiar with snapshot testing?
- Start with simple cases like API responses or HTML strings. Document common patterns (e.g., partial snapshots for APIs) and pair adoption with a workshop to ease the transition.
- Does this package support testing PDFs or images?
- Yes, since version 2.1.0, you can test binary outputs like PDFs or images using `toMatchImageSnapshot()`. This is ideal for Laravel apps generating dynamic visual content.
- How do I update snapshots in CI without breaking tests?
- Use the `--update-snapshots` flag during development or in CI for intentional changes. Review diffs in PRs to ensure updates are deliberate, then commit the new snapshots.
- Are there alternatives to this package for Laravel/Pest?
- If you’re not using Pest, you’d need `spatie/phpunit-snapshot-assertions` directly. For Pest users, this package is the most integrated option, offering a Pest-native API without PHPUnit migration.