Skip to content

Commit

Permalink
Add extra ts transformer mapping test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Mar 20, 2024
1 parent 66e2510 commit 3d2cc18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Spatie\LaravelData\PaginatedDataCollection;
use Spatie\LaravelData\Support\Lazy\ClosureLazy;
use Spatie\LaravelData\Support\TypeScriptTransformer\DataTypeScriptTransformer;
use Spatie\LaravelData\Tests\Fakes\DataWithMapper;
use Spatie\LaravelData\Tests\Fakes\SimpleData;

use function Spatie\Snapshots\assertMatchesSnapshot as baseAssertMatchesSnapshot;
Expand Down Expand Up @@ -159,7 +160,7 @@ public function __construct(
assertMatchesSnapshot($transformer->transform($reflection, 'DataObject')->transformed);
});

it('outputs types with properties using their mapped name', function () {
it('outputs types with properties using their mapped name on a property', function () {
$config = TypeScriptTransformerConfig::create();

$data = new class ('Good job Ruben', 'Hi Ruben') extends Data {
Expand All @@ -179,6 +180,17 @@ public function __construct(
assertMatchesSnapshot($transformer->transform($reflection, 'DataObject')->transformed);
});

it('outputs types with properties using their mapped name on a class', function () {
$config = TypeScriptTransformerConfig::create();

$transformer = new DataTypeScriptTransformer($config);
$reflection = new ReflectionClass(DataWithMapper::class);

expect($transformer->canTransform($reflection))->toBeTrue();
assertMatchesSnapshot($transformer->transform($reflection, 'DataObject')->transformed);
});


it('it respects a TypeScript property optional attribute', function () {
$config = TypeScriptTransformerConfig::create();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
cased_property: string;
data_cased_property: {%Spatie\LaravelData\Tests\Fakes\SimpleData%};
data_collection_cased_property: Array<{%Spatie\LaravelData\Tests\Fakes\SimpleData%}>;
}

0 comments on commit 3d2cc18

Please sign in to comment.