fix: add tests and refactor slug utils

This commit is contained in:
Oliver Eyton-Williams
2019-09-26 16:27:26 +02:00
committed by mrugesh
parent 9c2f1ffd82
commit 3dc4e5897d
3 changed files with 53 additions and 4 deletions

48
utils/slugs.test.js Normal file
View File

@ -0,0 +1,48 @@
/* global describe expect it */
const slugs = require('./slugs');
describe('dasherize', () => {
const { dasherize } = slugs;
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('removes everything except letters, numbers, - and .', () => {
expect(dasherize('1a!"£$%^*()_+=-.b2')).toBe('1a-.b2');
});
});
describe('nameify', () => {
const { nameify } = slugs;
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', () => {
const { unDasherize } = slugs;
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');
});
});