diff --git a/src/type/resolved/SlugType.js b/src/type/resolved/SlugType.js index 0bca0d5..1b01443 100644 --- a/src/type/resolved/SlugType.js +++ b/src/type/resolved/SlugType.js @@ -53,6 +53,8 @@ class SlugType extends ResolvedType { return slugify(model?.[property], { lower: true, + strict: true, + trim: true, }); } } diff --git a/src/type/resolved/SlugType.test.js b/src/type/resolved/SlugType.test.js index 15f97d9..6aed09d 100644 --- a/src/type/resolved/SlugType.test.js +++ b/src/type/resolved/SlugType.test.js @@ -29,6 +29,14 @@ test('SlugType.of(name).resolve({name: \'Testing the Slug\')) returns \'testing- t.is(SlugType.of('name').resolve({name: 'Testing the Slug'}), 'testing-the-slug'); }); +test('SlugType.of(name).resolve({name: \' Trimming whitespace \')) returns \'trimming-whitespace\'', t => { + t.is(SlugType.of('name').resolve({name: ' Trimming whitespace '}), 'trimming-whitespace'); +}); + test('SlugType.of(name).resolve()) returns \'\'', t => { t.is(SlugType.of('name').resolve(), ''); }); + +test('SlugType.of(special).resolve({special: \'don\'t include special characters\')) returns \'dont-include-special-characters\'', t => { + t.is(SlugType.of('special').resolve({special: 'don\'t include special characters'}), 'dont-include-special-characters'); +});