Unit tests for a pure function (no mocks)
在 Playground 中试用提示词
Write Vitest unit tests for this pure function. Cover the happy path, edge cases (empty input, boundaries, unicode) and one property you expect to always hold. No mocks.
{function_code}示例输出
Example run: function_code = the slugify() helper from this codebase. All 6 tests pass.
import { describe, expect, it } from 'vitest';
import { slugify } from './utils';
describe('slugify', () => {
it('lowercases and joins words with dashes', () => {
expect(slugify('Hello World')).toBe('hello-world');
});
it('collapses spaces, underscores and repeated dashes', () => {
expect(slugify('a b__c--d')).toBe('a-b-c-d');
});
it('trims leading and trailing separators', () => {
expect(slugify(' -Hello- ')).toBe('hello');
});
it('returns an empty string for empty or symbol-only input', () => {
expect(slugify('')).toBe('');
expect(slugify('!!!')).toBe('');
});
it('drops non-ASCII letters (current behavior)', () => {
expect(slugify('Café 안녕')).toBe('caf');
});
it('never exceeds 80 characters', () => {
expect(slugify('a'.repeat(200)).length).toBeLessThanOrEqual(80);
});
});
