Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions specs/Path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down