Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Snapshots
A variety of snapshot assertions are available to help you test your HTML and DOM output in craft-pest. In many places you can simply expect an object
->toMatchSnapshot()
and Pest will handle the rest for you.The two entrypoints to snapshotting are,
expect($object)->toMatchSnapshot()
$this->assertMatchesSnapshot()
For example, responses, DOM Lists, and views are all snapshotable.
Elements
Many elements can be snapshotted as well. When using assertions Pest will automatically handle the conversion from an Element to a snapshot.
Unfortunately, Pest is not smart enough to properly snapshot elements in an expectation so you must call
->toSnapshot()
on them first.Attributes
Only a subset of attributes from the element are snapshotted so dynamic fields do not create unexpected failures. For example, the
$entry->postDate
defaults to the current time when the entry was generated. That means running the test on Tuesday and again on Wednesday would fail the test because thepostDate
would be Tuesday in the initial snapshot and Wednesday during the comparison.If you'd like to include additional attributes in the snapshot you can pass them as an array to the
->toSnapshot()
method. For example,