X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Flib%2Frouter.js;h=4047b16ad3ba4dd74e4ba2e9f6929c4b4d62f626;hb=32c91cbeb87eac23e6a4ad646dd4a94bebc52fa9;hp=f9a2401eba045bb3b0972acac39287a07a907a01;hpb=1296167385b38ca226f17c3a87ac2135d53c769b;p=squeep-api-dingus diff --git a/test/lib/router.js b/test/lib/router.js index f9a2401..4047b16 100644 --- a/test/lib/router.js +++ b/test/lib/router.js @@ -1,12 +1,10 @@ -/* eslint-disable capitalized-comments */ -/* eslint-env mocha */ 'use strict'; -const assert = require('assert'); -const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require +const assert = require('node:assert'); +const sinon = require('sinon'); const Router = require('../../lib/router'); -const PathParameter = require('../../lib/router/path-parameter') -const { DingusError } = require('../../lib/errors'); +const PathParameter = require('../../lib/router/path-parameter'); +const { DingusError, RouterNoPathError, RouterNoMethodError } = require('../../lib/errors'); const noExpectedException = 'did not get expected exception'; @@ -260,7 +258,7 @@ describe('Router', function () { router.on('FLARP', urlPath, stubHandler); assert.fail('expected an exception'); } catch (e) { - assert.strictEqual(e.name, 'DingusError'); + assert(e instanceof DingusError); assert.strictEqual(e.message, 'invalid method \'FLARP\''); } }); @@ -298,6 +296,7 @@ describe('Router', function () { const { handler } = router.lookup(method, path, ctx); assert.strictEqual(handler, stubHandler); + assert.strictEqual(ctx.matchedPath, urlPath); }); it('does not find handler with trailing slash', function () { router.ignoreTrailingSlash = false; @@ -310,8 +309,7 @@ describe('Router', function () { router.lookup(method, path, ctx); assert.fail(noExpectedException); } catch (e) { - assert(e instanceof DingusError); - assert.strictEqual(e.message, 'NoPath'); + assert(e instanceof RouterNoPathError); } }); it('finds handler', function () { @@ -352,8 +350,7 @@ describe('Router', function () { router.lookup(method, path, ctx); assert.fail(noExpectedException); } catch (e) { - assert(e instanceof DingusError); - assert.strictEqual(e.message, 'NoMethod'); + assert(e instanceof RouterNoMethodError); } }); it('does not lookup non-existent path', async function () { @@ -364,8 +361,7 @@ describe('Router', function () { router.lookup(method, path, ctx); assert.fail(noExpectedException); } catch (e) { - assert(e instanceof DingusError); - assert.strictEqual(e.message, 'NoPath'); + assert(e instanceof RouterNoPathError); } });