Back to all reviewers

Keep tests simple

vercel/ai
Based on 6 comments
TypeScript

Tests should be straightforward, explicit, and free from complex logic or indirection. Avoid "magic" in tests that makes them harder to understand at a glance. When designing tests:

Testing TypeScript

Reviewer Prompt

Tests should be straightforward, explicit, and free from complex logic or indirection. Avoid “magic” in tests that makes them harder to understand at a glance. When designing tests:

  1. Prefer explicit setup over helper functions that hide details: ```javascript // Avoid: const store = initStore(chats);

// Prefer: const store = new ChatStore({ chats });


2. Inline test data directly rather than using complex extraction logic:
```javascript
// Avoid:
const text = content
  .filter(item => item.type === 'text' && !item.thought)
  .map(item => item.text)
  .join('');

// Prefer:
expect(content).toMatchInlineSnapshot(`
  [
    { "type": "text", "text": "Hello, World!" },
  ]
`);
  1. Test one behavior per test case so they can fail independently and provide clear signals about what’s broken.

  2. Make tests deterministic by stubbing variable elements like dates, timeouts, and IDs.

Simple tests are easier to understand, debug, and maintain, serving effectively as both verification tools and living documentation of expected behavior.

6
Comments Analyzed
TypeScript
Primary Language
Testing
Category

Source Discussions