diff --git a/specs/Path.spec.js b/specs/Path.spec.js index bacbf07a70..ce22062741 100644 --- a/specs/Path.spec.js +++ b/specs/Path.spec.js @@ -47,6 +47,20 @@ describe('Path.extractParams', function () { }); }); + describe('and the pattern is optional', function () { + var pattern = 'comments/:id?/edit' + + describe('and the path matches with supplied param', function () { + it('returns an object with the params', function () { + expect(Path.extractParams(pattern, 'comments/123/edit')).toEqual({ id: '123' }); + }); + }); + describe('and the path matches without supplied param', function () { + it('returns an object with param set to null', function () { + expect(Path.extractParams(pattern, 'comments/edit')).toEqual({id: null}); + }); + }); + }); describe('and the path does not match', function () { it('returns null', function () { expect(Path.extractParams(pattern, 'users/123')).toBe(null); @@ -166,6 +180,18 @@ describe('Path.injectParams', function () { }); }); + describe('and a param is optional', function () { + var pattern = 'comments/:id?/edit'; + + it('returns the correct path when param is supplied', function () { + expect(Path.injectParams(pattern, {id:'123'})).toEqual('comments/123/edit'); + }); + + it('returns the correct path when param is not supplied', function () { + expect(Path.injectParams(pattern, {})).toEqual('comments/edit'); + }); + }); + describe('and all params are present', function () { it('returns the correct path', function () { expect(Path.injectParams(pattern, { id: 'abc' })).toEqual('comments/abc/edit');