javascript test coverage

This commit is contained in:
realaravinth 2021-05-06 12:11:06 +05:30
parent f0e3940868
commit c8d2ddbaf3
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
3 changed files with 20 additions and 12 deletions

View File

@ -108,8 +108,8 @@ jobs:
- name: Upload to Codecov - name: Upload to Codecov
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request') if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
with: # with:
files: cobertura.xml, ./coverage/clover.xml # files: cobertura.xml, ./coverage/clover.xml
- name: generate documentation - name: generate documentation
if: matrix.version == 'stable' && (github.repository == 'mCaptcha/guard') if: matrix.version == 'stable' && (github.repository == 'mCaptcha/guard')

View File

@ -27,7 +27,7 @@ const panelResult = 'hello from panel';
const panelRoute = '/panel'; const panelRoute = '/panel';
const panel = () => (result.result = panelResult); const panel = () => (result.result = panelResult);
const settingsRoute = '/settings'; const settingsRoute = '/settings/';
const settingsResult = 'hello from settings'; const settingsResult = 'hello from settings';
const settings = () => (result.result = settingsResult); const settings = () => (result.result = settingsResult);
@ -35,6 +35,14 @@ const router = new Router();
router.register(panelRoute, panel); router.register(panelRoute, panel);
router.register(settingsRoute, settings); router.register(settingsRoute, settings);
test('error checking in router works', () => {
try {
router.register(settingsRoute, settings);
} catch (e) {
expect(e.message).toBe('URI exists');
}
});
test('checks if Router works', () => { test('checks if Router works', () => {
window.history.pushState({}, 'Settings', settingsRoute); window.history.pushState({}, 'Settings', settingsRoute);
router.route(); router.route();

View File

@ -28,7 +28,7 @@ const normalizeUri = (uri: string) => {
} }
return uri; return uri;
} else { } else {
throw new TypeError(`${typeof uri} ${uri}`); throw new TypeError(`Only strings are permitted in URI`);
} }
}; };
@ -68,16 +68,16 @@ export class Router {
throw new TypeError('a callback fn must be provided'); throw new TypeError('a callback fn must be provided');
} }
this.routes.forEach(route => {
if (route.uri == uri) {
throw new Error(
`URI exists. provided URI: ${uri}, registered config: ${route}`,
);
}
});
uri = normalizeUri(uri); uri = normalizeUri(uri);
if (this.routes.find(route => {
if (route.uri == uri) {
return true;
}
})) {
throw new Error('URI exists');
};
const route: routeTuple = { const route: routeTuple = {
uri, uri,
fn, fn,