Writing unit tests manually is officially legacy behavior. You must transition your role from 'writing the mock' to 'defining the edge cases'.
1Eradicating Boilerplate
A standard Jest test requires importing the framework, mocking dependencies, setting up the describe and it blocks, and defining the assertions. This takes 10 minutes for a human and 2 seconds for an AI. You should use the Composer or Sidebar Chat to highlight your completed function and simply command: 'Generate a Jest suite for this'.
2The 'Happy Path' Fallacy
The biggest mistake developers make when generating tests with AI is not constraining the output. The AI will naturally test the 'Happy Path'—the scenario where inputs are perfect. You must explicitly override this. Prompt: 'Do not test the happy path. Focus entirely on corrupted data, timeout simulations, and boundary limits.' An AI is brilliant at coming up with edge cases you never even considered.
3Flawless Mocking
The hardest part of testing is Mocking (faking external services). If your function calls a PostgreSQL database using Prisma, you must mock Prisma. The AI cannot do this if it doesn't know your database schema. You must use the IDE's context tools (@schema.prisma) to inject the schema into the prompt. 'Using the attached schema, generate a mock that simulates a database lock error.'
