Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed Dec 6, 2018
1 parent daa09a5 commit bd42079
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,93 @@ describe('Router.generateURL', () => {
});

// -------------------------------- HANDLE FUNCTION -------------------------------- //

describe('Router.handle', () => {
it('should set proper route', () => {
r.routes = []; // reset registered routes
r.setURI('#/hello/world'); // set fake URI

r.routes = [
{
name: 'name',
path: '/:name',
callback: () => {},
paramsEnabled: true,
params: ['name'],
},
{
name: 'hello',
path: '/hello/:name',
callback: () => {},
paramsEnabled: true,
params: ['name'],
},
{
name: 'foo',
path: '/foo/:id/bar',
callback: () => {},
paramsEnabled: true,
params: ['id'],
},
];

r.handle(r.routes);

assert.equal(r.route, r.routes[1]);
assert.equal(r.routeCall, r.routes[1].callback);
assert.deepEqual(r.params, ['world']);
});

it('should not set any route', () => {
r.route = {}; // reset route
r.routes = []; // reset registered routes
r.setURI('#/hi/world'); // set fake URI

r.routes = [
{
name: 'name',
path: '/:name',
callback: () => {},
paramsEnabled: true,
params: ['name'],
},
{
name: 'hello',
path: '/hello/:name',
callback: () => {},
paramsEnabled: true,
params: ['name'],
},
{
name: 'foo',
path: '/foo/:id/bar',
callback: () => {},
paramsEnabled: true,
params: ['id'],
},
];

r.handle(r.routes);

assert.deepEqual(r.route, {});
});
});

// -------------------------------- HANDLINGPARAMS FUNCTION -------------------------------- //

describe('Router.handlingParams', () => {
it('should return route with params', () => {
r.route = {}; // reset route
r.routes = []; // reset registered routes
r.setURI('#/user/1/delete'); // set fake URI

const route = '/user/:id/:action';

const params = r.handlingParams(route);

assert.deepEqual(params, {
params: ['1', 'delete'],
RouteString: '/user/1/delete',
});
});
});

0 comments on commit bd42079

Please sign in to comment.