4 const assert
= require('node:assert');
5 const PathParameter
= require('../../../lib/router/path-parameter');
7 describe('PathParameter', function () {
8 beforeEach(function () {
9 PathParameter
._flush();
12 it('requires a parameter', function () {
13 assert
.throws(() => new PathParameter(), RangeError
);
16 it('requires parameter be a string', function () {
17 assert
.throws(() => new PathParameter({}), RangeError
);
20 it('creates a parameter object', function () {
21 const p
= new PathParameter('foo');
22 assert(p
instanceof PathParameter
);
23 assert
.strictEqual(p
.parameter
, 'foo');
26 it('duplicate parameters are the same object', function () {
27 const p1
= new PathParameter('foo');
28 const p2
= new PathParameter('foo');
29 assert
.strictEqual(p1
, p2
);
30 assert(Object
.is(p1
, p2
));
33 it('shows itself', function () {
34 const p
= new PathParameter('foo');
35 assert
.strictEqual(`${p}`, 'foo');
38 it('serializes', function () {
39 const p
= new PathParameter(':foo');
40 const result
= JSON
.stringify(p
);
41 assert
.strictEqual(result
, '":foo"');
44 it('parameters are immutable', function () {
45 const p
= new PathParameter('foo');
46 assert
.throws(() => p
.parameter
= 'bar', TypeError
);