-/* 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';
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\'');
}
});
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;
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 () {
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 () {
router.lookup(method, path, ctx);
assert.fail(noExpectedException);
} catch (e) {
- assert(e instanceof DingusError);
- assert.strictEqual(e.message, 'NoPath');
+ assert(e instanceof RouterNoPathError);
}
});