Files
freeCodeCamp/utils/slugs.test.ts
palash-signoz 004c5b6fb6 chore(utils): ts-migration of utils/slugs (#44921)
* chore: utils is added in the tsconfig

* test(util): test and test function is updated to typescript

* chore: add tsconfig for utils

* fix: exclude files importing from client/

* fix: refactor to just export functions

* chore: add emitted files to prettierignore

* fix: add new tsconfig to eslint project

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2022-03-29 08:51:13 -07:00

50 lines
1.5 KiB
TypeScript

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');
});
});