-
-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ->toMatchSnapshot()
will not work with @csrf
#946
Comments
cc @freekmurze |
In our projects we add a function to strip out the token of a value before snapshotting that value. It would be nice if there were some helper methods on the Pest snapshot methods for this. Or maybe let the
|
There is a similar problem with I think it would be nice if the most common "problems" would be handled automatically by Pest. But the idea with the callable sounds nice for custom use cases. 👍 |
I think the callable makes the most sense. Perhaps for Livewire, it could be a hook or something via the Pest Livewire plugin, and For example, we could have a method like |
@owenvoke Sounds amazing 🎉 |
@gehrisandro I like the idea of |
Here my current quick and dirty fix for Livewire: expect(str($component->html(stripInitialData: true))->replaceMatches('/wire:id="[0-9a-zA-Z]*"/', ''))
->toMatchSnapshot(); If we all agree on the suggestion by @owenvoke I can help here. I should find some time by the end of this week. |
And here is my fix for the $response = get($url);
$content = $response->content();
$newContent = collect(
str($content)->explode("\n")
)
->reject(fn (string $line) => str($line)->contains('_token'))
->reject(fn (string $line) => str($line)->contains('link rel="preload" as="style"'))
->implode("\n");
$response->setContent($newContent);
expect($response)->toMatchSnapshot(); |
Here my PR |
CSRF tokens can possibly be more easily stripped by using |
What Happened
When I use
expect($response)->toMatchSnapshot()
and I use the@csrf
directory the test will fail because the csrf is changed on every request.`I think there should be a way to ignore the
@csrf
directive on snapshot testing.How to Reproduce
@csrf
expect($response)->toMatchSnapshot()
.Sample Repository
https://github.com/alexmanase/pest-snapshost-csrf-issue
Pest Version
2.16.1
PHP Version
8.2.8
Operation System
macOS
Notes
No response
The text was updated successfully, but these errors were encountered: