Download and import the JSON preset
Save `unit-and-integration-test-generator.json` and import it into Vezz me.
Download the Unit & Integration Test Generator JSON preset for Vezz me. Highlight any function, class, or API handler to generate edge-case unit tests.
Instead of switching tabs and rebuilding context, highlight the exact passage that slowed you down and press your shortcut (default: Ctrl+Shift+X or Cmd+Shift+X on macOS, fully customizable in settings).
export function consumeTokens(bucket: TokenBucket, tokens: number, nowMs: number): boolean { const elapsed = (nowMs - bucket.lastRefillMs) / 1000; bucket.currentTokens = Math.min(bucket.capacity, bucket.currentTokens + elapsed * bucket.refillRatePerSec); bucket.lastRefillMs = nowMs; if (bucket.currentTokens >= tokens) { bucket.currentTokens -= tokens; return true; } return false; }
**Edge-Case Test Matrix**:
1. Consuming when tokens are available (`true`).
2. Consuming more tokens than capacity (`false` immediately).
3. Zero tokens requested (`tokens = 0`).
4. Clock drift backwards (`nowMs < bucket.lastRefillMs`).
5. Partial fractional token accumulation.
```ts
import { describe, it, expect } from 'vitest';
import { consumeTokens } from './rateLimiter';
describe('consumeTokens', () => {
it('should refill tokens up to capacity but not exceed it', () => {
const bucket = { capacity: 10, currentTokens: 5, refillRatePerSec: 10, lastRefillMs: 1000 };
expect(consumeTokens(bucket, 10, 2000)).toBe(true);
expect(bucket.currentTokens).toBe(0);
});
it('should handle clock skew gracefully if nowMs is in the past', () => {
const bucket = { capacity: 10, currentTokens: 5, refillRatePerSec: 10, lastRefillMs: 2000 };
// If system clock jumped backwards 500ms, elapsed is negative!
consumeTokens(bucket, 1, 1500);
// Flag: Note that elapsed < 0 will subtract tokens in your current implementation!
});
});
```
Copy the system prompt below or download the .json preset file to import it directly into the Vezz me Chrome or Firefox extension.
Focuses on boundary edge cases (empty strings, zero, negative numbers, network timeouts, concurrent retries) rather than repetitive happy-path tests.
Act as a Principal Software Engineer writing production tests for the selected code: 1) Edge-Case Matrix: identify boundary values, off-by-one errors, empty arrays/null inputs, network timeouts, and concurrency races, 2) Test Suite: write clean, self-contained test cases (using Vitest/Jest for TS/JS, pytest for Python, or testing for Go) with descriptive test names ('should return 400 when X is empty'), and 3) Mocking Guidance: mock external I/O cleanly without over-mocking internal business logic.Save `unit-and-integration-test-generator.json` and import it into Vezz me.
Select the implementation and press your shortcut (default: Ctrl+Shift+X).
Paste the generated test cases directly into your codebase and run `npm test` or `pytest`.
Yes! You can append 'using Vitest', 'using pytest', 'using Go standard library', or 'using Rust #[test]' to your query.
Yes—the prompt explicitly checks for unhandled Promise rejections, timeout exceptions, and HTTP non-2xx status codes.
Use our Senior Engineer Code Reviewer preset.
Install Vezz me free, highlight text on any webpage, and press your customizable shortcut (default: Ctrl+Shift+X or Cmd+Shift+X on Mac) to get an answer right beside the source.