diff --git a/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_with__toSnapshot_.snap b/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_with__toSnapshot_.snap new file mode 100644 index 00000000..afd4f5f9 --- /dev/null +++ b/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_with__toSnapshot_.snap @@ -0,0 +1,3 @@ +{ + "key": "
\n
\n
\n

Snapshot<\/h1>\n <\/div>\n <\/div>\n <\/div>" +} \ No newline at end of file diff --git a/tests/Features/Expect/toMatchSnapshot.php b/tests/Features/Expect/toMatchSnapshot.php index ed5c8458..8196cc0b 100644 --- a/tests/Features/Expect/toMatchSnapshot.php +++ b/tests/Features/Expect/toMatchSnapshot.php @@ -103,6 +103,26 @@ test('pass with array', function () { ])->toMatchSnapshot(); }); +test('pass with `toSnapshot`', function () { + TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT)); + + $object = new class($this->snapshotable) + { + public function __construct(protected string $snapshotable) + { + } + + public function toSnapshot() + { + return json_encode([ + 'key' => $this->snapshotable, + ], JSON_PRETTY_PRINT); + } + }; + + expect($object)->toMatchSnapshot(); +}); + test('failures', function () { TestSuite::getInstance()->snapshots->save($this->snapshotable);