url-slugify
Version:
Creates SEO friendly URL slugs with multiple language support
45 lines (30 loc) • 1.79 kB
JavaScript
const chai = require('chai');
const URLSlug = require('../src/URLSlugify');
const expect = chai.expect;
describe('Slugify', () => {
describe('Ensure slugs are generated from strings', () => {
const urlSlug = new URLSlug();
it('should replace whitespaces with replacement', () => {
expect(urlSlug.slugify('this is a test title', '-').indexOf('this-is-a-test-title')).to.not.eql(-1);
});
it('should remove trailing space if any', () => {
expect(urlSlug.slugify('this is a test title ').indexOf('this-is-a-test-title')).to.not.eql(-1);
});
it('should remove not allowed characters', () => {
expect(urlSlug.slugify('this. is. a test title').indexOf('this-is-a-test-title')).to.not.eql(-1);
expect(urlSlug.slugify('this] is[ a test title').indexOf('this-is-a-test-title')).to.not.eql(-1);
expect(urlSlug.slugify('this& is&& a &&test title').indexOf('this-is-a-test-title')).to.not.eql(-1);
expect(urlSlug.slugify('£!+this /$&()is a. test >><<:;title').indexOf('this-is-a-test-title')).to.not.eql(-1);
});
it('should slugify title using optional separators \'_\' or \'~\'', () => {
expect(urlSlug.slugify('this is a test title', '_').indexOf('this_is_a_test_title')).to.not.eql(-1);
expect(urlSlug.slugify('this is a test title', '~').indexOf('this~is~a~test~title')).to.not.eql(-1);
});
it('should remove all whitespaces using the optional \'\'\'\' separator', () => {
expect(urlSlug.slugify('this is a test title', '\'\'').indexOf('thisisatesttitle')).to.not.eql(-1);
});
it('should replace accents characters with seo-friendly options', () => {
expect(urlSlug.slugify('thís îs ã tést tìtlẽ', '-').indexOf('this-is-a-test-title')).to.not.eql(-1);
});
});
});