web/src/utils/fetch-data.test.ts

37 lines · 1066 bytes

 1import { describe, it, expect } from 'vitest';
 2import { slugify } from './fetch-data';
 3
 4describe('slugify', () => {
 5  it('lowercases and replaces spaces with hyphens', () => {
 6    expect(slugify('Hello World')).toBe('hello-world');
 7  });
 8
 9  it('replaces & with "and"', () => {
10    expect(slugify('Privacy & Security')).toBe('privacy-and-security');
11  });
12
13  it('replaces + with "and"', () => {
14    expect(slugify('Tools + Tips')).toBe('tools-and-tips');
15  });
16
17  it('removes question marks', () => {
18    expect(slugify('What is Privacy?')).toBe('what-is-privacy');
19  });
20
21  it('handles multiple spaces', () => {
22    expect(slugify('a  b   c')).toBe('a--b---c');
23  });
24
25  it('returns empty string for empty input', () => {
26    expect(slugify('')).toBe('');
27  });
28
29  it('returns empty string for undefined-like input', () => {
30    // eslint-disable-next-line @typescript-eslint/no-explicit-any
31    expect(slugify(undefined as any)).toBe('');
32  });
33
34  it('handles combined special characters', () => {
35    expect(slugify('Q&A + FAQ?')).toBe('qanda-and-faq');
36  });
37});