forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslugs.test.ts
49 lines (43 loc) · 1.51 KB
/
slugs.test.ts
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
import { dasherize, nameify, unDasherize } from './slugs';
describe('dasherize', () => {
it('returns a string', () => {
expect(dasherize('')).toBe('');
});
it('converts characters to lower case', () => {
expect(dasherize('UPPERCASE')).toBe('uppercase');
});
it('converts spaces to dashes', () => {
expect(dasherize('the space between')).toBe('the-space--between');
});
it('converts dots to dashes', () => {
expect(dasherize('the..dots.. between')).toBe('the--dots---between');
});
it('trims off surrounding whitespace', () => {
expect(dasherize(' the space between ')).toBe('the-space--between');
});
it('removes everything except letters, numbers and -', () => {
expect(dasherize('1a!"£$%^*()_+=-.b2')).toBe('1a--b2');
});
});
describe('nameify', () => {
it('returns a string', () => {
expect(nameify('')).toBe('');
});
it('removes everything except letters, numbers and spaces', () => {
expect(nameify('1A !"£$%^*()_+=-.b 2')).toBe('1A b 2');
});
});
describe('unDasherize', () => {
it('returns a string', () => {
expect(unDasherize('')).toBe('');
});
it('converts dashes to spaces', () => {
expect(unDasherize('the-space--between')).toBe('the space between');
});
it('removes everything except letters, numbers and spaces', () => {
expect(unDasherize('1A !"£$%^*()_+=-.b 2')).toBe('1A b 2');
});
it('trims off surrounding whitespace', () => {
expect(unDasherize('--the-space--between----')).toBe('the space between');
});
});