Skip to content

Commit

Permalink
Increase route-template coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyrno42 committed Aug 15, 2022
1 parent 6a2fdd3 commit ae1be66
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/route-template/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { isRouteTemplate, routeTemplate } from '../src';
import { cleanRoot, cleanRoute } from '../src/utils';

describe('cleanRoot', () => {
test('cleanRoot works', () => {
expect(cleanRoot('/')).toBe('');
expect(cleanRoot('/test')).toBe('/test');
expect(cleanRoot('/test/')).toBe('/test');
expect(cleanRoot('/test/path')).toBe('/test/path');
expect(cleanRoot('/test/path/')).toBe('/test/path');
});
});

describe('cleanRoute', () => {
test('cleanRoute works', () => {
expect(cleanRoute('/')).toBe('');
expect(cleanRoute('/test')).toBe('test');
expect(cleanRoute('/test/')).toBe('test/');
expect(cleanRoute('/test/path')).toBe('test/path');
expect(cleanRoute('/test/path/')).toBe('test/path/');
});
});

describe('isRouteTemplate', () => {
test('happy path', () => {
const method = routeTemplate('/test/path');

expect(isRouteTemplate(method)).toBe(true);
});

test('not function', () => {
const method = 'not a function';

expect(isRouteTemplate(method)).toBe(false);
});

test('missing routePath', () => {
const method = () => {};

expect(isRouteTemplate(method)).toBe(false);
});

test('routepath is not a string', () => {
const method = routeTemplate('/test/path');
(method as any).routePath = 1;

expect(isRouteTemplate(method)).toBe(false);
});

test('missing configure', () => {
const method = routeTemplate('/test/path');
delete (method as any).configure;

expect(isRouteTemplate(method)).toBe(false);
});
});

0 comments on commit ae1be66

Please sign in to comment.