diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 149e9dc7..45298ab1 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -108,8 +108,8 @@ jobs: - name: Upload to Codecov if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request') uses: codecov/codecov-action@v1 - with: - files: cobertura.xml, ./coverage/clover.xml + # with: + # files: cobertura.xml, ./coverage/clover.xml - name: generate documentation if: matrix.version == 'stable' && (github.repository == 'mCaptcha/guard') diff --git a/templates/router.test.ts b/templates/router.test.ts index 36756751..ac8a7e8a 100644 --- a/templates/router.test.ts +++ b/templates/router.test.ts @@ -27,7 +27,7 @@ const panelResult = 'hello from panel'; const panelRoute = '/panel'; const panel = () => (result.result = panelResult); -const settingsRoute = '/settings'; +const settingsRoute = '/settings/'; const settingsResult = 'hello from settings'; const settings = () => (result.result = settingsResult); @@ -35,6 +35,14 @@ const router = new Router(); router.register(panelRoute, panel); 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', () => { window.history.pushState({}, 'Settings', settingsRoute); router.route(); diff --git a/templates/router.ts b/templates/router.ts index ed337e99..e803fdd6 100644 --- a/templates/router.ts +++ b/templates/router.ts @@ -28,7 +28,7 @@ const normalizeUri = (uri: string) => { } return uri; } 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'); } - this.routes.forEach(route => { - if (route.uri == uri) { - throw new Error( - `URI exists. provided URI: ${uri}, registered config: ${route}`, - ); - } - }); - uri = normalizeUri(uri); + if (this.routes.find(route => { + if (route.uri == uri) { + return true; + } + })) { + throw new Error('URI exists'); + }; + const route: routeTuple = { uri, fn,