Got it! If your generateAsciiArt function is not hardcoded and can dynamically generate ASCII art for any object description (e.g., using an AI model, a vector database of shapes, or some clever procedural generation), then the test file should reflect that flexibility.
Since we can't predict exact outputs for arbitrary inputs in unit tests, we'll focus on:
- Ensuring the output is a non-empty string.
- Ensuring the output looks like ASCII art (contains common characters like
/, \, -, |, etc.).
- Ensuring the output is different for different inputs.
- Optionally: checking basic structure (like multiple lines).
✅ Sample Vitest File (asciiArtGenerator.test.ts)
import { describe, it, expect } from 'vitest';
import { generateAsciiArt } from './asciiArtGenerator';
describe('generateAsciiArt', () => {
it('should return a non-empty string for any valid description', () => {
const result = generateAsciiArt('robot');
expect(typeof result).toBe('string');
expect(result.trim()).not.toBe('');
});
it('should return different results for different descriptions', () => {
const catArt = generateAsciiArt('cat');
const dogArt = generateAsciiArt('dog');
expect(catArt).not.toBe(dogArt);
});
it('should return multi-line strings resembling ASCII art', () => {
const art = generateAsciiArt('spaceship');
const lines = art.split('\n');
expect(lines.length).toBeGreaterThan(1); // At least two lines
expect(lines.some(line => /[-\\\/\|]/.test(line))).toBe(true); // Contains ASCII-like characters
});
it('should handle edge-case descriptions gracefully', () => {
const empty = generateAsciiArt('');
expect(empty).toBeDefined();
expect(empty.trim()).not.toBe('');
const veryLongDescription = 'A futuristic city with flying cars and neon lights'.repeat(5);
const art = generateAsciiArt(veryLongDescription);
expect(art).toBeDefined();
expect(art.trim()).not.toBe('');
});
});
📦 Notes
- This assumes that
generateAsciiArt does something clever under the hood — maybe it's calling an LLM, querying a database, or using generative algorithms.
- The tests are behavioral, not value-based, because we don’t know what the ASCII art for "spaceship" or "dragon" should look like exactly.
- If you're using a deterministic backend or have expected outputs, you could add snapshot testing too!
🧪 Optional: Add Snapshot Testing (if stable output)
If your function gives consistent results for the same input (which is likely if it's deterministic), use snapshot testing:
it('should match snapshot for "mountain"', () => {
const art = generateAsciiArt('mountain');
expect(art).toMatchSnapshot();
});
This will store the first generated ASCII art of a mountain and check future runs against it.
Let me know if you'd like to integrate this with actual AI or procedural generation logic!