Snapshots Plugin

The Snapshots Plugin for Pest adds snapshot testing capabilities to Pest.

Source code:

Snapshot tests are a very useful tool whenever you want to make sure things don't change unexpectedly. Find more about snapshot testing here:

Install the plugin using Composer:

composer require spatie/pest-plugin-snapshots --dev


The assertMatchesSnapshot() function asserts the given string matches the existing snapshot.

use function Spatie\Snapshots\assertMatchesSnapshot;
use function Pest\Laravel\get;

it('renders correctly', function () {
    $html = get('/')->getContent();


If you’re working with specific data like JSON or XML, you’re better off using a dedicated assertMatchesJsonSnapshot or assertMatchesXmlSnapshot method, which will save snapshots as .json or .xml files, and provide a better diff when the snapshot doesn’t match:

  • assertMatchesSnapshot()
  • assertMatchesFileHashSnapshot()
  • assertMatchesFileSnapshot()
  • assertMatchesHtmlSnapshot()
  • assertMatchesJsonSnapshot()
  • assertMatchesObjectSnapshot()
  • assertMatchesTextSnapshot()
  • assertMatchesXmlSnapshot()
  • assertMatchesYamlSnapshot()

Note that, by default, snapshots are stored in a tests/__snapshots__ directory.

Also, when you expect a changed value, you may need to run the -d --update-snapshots flag to update the existing snapshots:

./vendor/bin/pest -d --update-snapshots

Next section: Changelog →