-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslug-service.unit.test.ts
More file actions
53 lines (39 loc) · 1.24 KB
/
slug-service.unit.test.ts
File metadata and controls
53 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { describe, expect, it } from 'vitest'
import { createSlug } from './slug-service'
describe('createSlug', () => {
it('converts text to a slug with lowercase characters', () => {
const text = 'Hello World'
const result = createSlug(text)
expect(result).toBe('hello-world')
})
it('replaces spaces with hyphens', () => {
const text = 'This is a test'
const result = createSlug(text)
expect(result).toBe('this-is-a-test')
})
it('removes special characters', () => {
const text = 'Hello, World!'
const result = createSlug(text)
expect(result).toBe('hello-world')
})
it('handles accented characters', () => {
const text = 'Café and Restaurant'
const result = createSlug(text)
expect(result).toBe('cafe-and-restaurant')
})
it('handles & characters', () => {
const text = 'Café & Restaurant'
const result = createSlug(text)
expect(result).toBe('cafe-and-restaurant')
})
it('returns an empty string if the input is an empty string', () => {
const text = ''
const result = createSlug(text)
expect(result).toBe('')
})
it('trims leading and trailing spaces', () => {
const text = ' Leading and trailing spaces '
const result = createSlug(text)
expect(result).toBe('leading-and-trailing-spaces')
})
})