Skip to content

damischa1/test-client-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prisma JSON Types Generator Test

Simple test that verifies Prisma JSON Types Generator works correctly.

How the test works

The test leverages TypeScript compiler to validate that JSON fields are typed correctly:

prisma.test.create({
  data: {
    testfield: {
      name: 'Test value'  // This must be TestType type
    }
  }
});

If TypeScript compiles ✅ = JSON types generator works
If TypeScript throws errors ❌ = JSON types generator doesn't work

Usage

# 1. Install dependencies
npm install

# 2. Run test (generates + tests automatically)
npm run test

The test automatically does:

  1. prisma generate - Generates Prisma client + JSON types
  2. tsc --noEmit --strict - Checks TypeScript types
  3. If both succeed → ✅ Test passed

Files

  • prisma/schema.prisma - Test model with testfield Json? field
  • src/types.ts - PrismaJson.TestType interface definition
  • src/index.ts - Simple test that uses typed fields
  • src/generated/ - Prisma generates client files here
  • tsconfig.json - TypeScript configuration with strict mode

Expected result

When test succeeds:

✅ All tests passed! JSON types are correctly generated.

When test fails, you'll see TypeScript errors that tell you what's wrong.

Testing failure scenario

To test that the test correctly catches failures, comment out the JSON types generator in prisma/schema.prisma:

# generator json {
#   provider = "prisma-json-types-generator"
# }

Then run npm test - the TypeScript compilation should fail, demonstrating that the test properly validates the generator's functionality.

Expected error when generator is disabled

When the JSON types generator is commented out or fails, you'll see this TypeScript error:

✔ Generated Prisma Client (6.18.0) to .\src\generated in 34ms

src/index.ts:15:7 - error TS2322: Type 'TestType' is not assignable to type 'NullableJsonNullValueInput | InputJsonValue | undefined'.
  Type 'TestType' is not assignable to type 'InputJsonObject'.
    Index signature for type 'string' is missing in type 'TestType'.

15       testfield: testField
         ~~~~~~~~~


Found 1 error in src/index.ts:15

This error occurs because:

  • Without the JSON types generator, Prisma treats JSON fields as generic InputJsonValue type
  • The PrismaJson.TestType interface is not recognized by the Prisma client
  • TypeScript cannot match our custom TestType with the generic JSON input type

This demonstrates that the JSON types generator is essential for proper TypeScript integration with JSON fields in Prisma.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published