minor cleanup of router parameter class
[squeep-api-dingus] / test / lib / router / path-parameter.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const PathParameter = require('../../../lib/router/path-parameter');
6
7 describe('PathParameter', function () {
8 beforeEach(function () {
9 PathParameter._flush();
10 });
11
12 it('requires a parameter', function () {
13 assert.throws(() => new PathParameter(), RangeError);
14 });
15
16 it('requires parameter be a string', function () {
17 assert.throws(() => new PathParameter({}), RangeError);
18 });
19
20 it('creates a parameter object', function () {
21 const p = new PathParameter('foo');
22 assert(p instanceof PathParameter);
23 assert.strictEqual(p.parameter, 'foo');
24 });
25
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));
31 });
32
33 it('shows itself', function () {
34 const p = new PathParameter('foo');
35 assert.strictEqual(`${p}`, 'foo');
36 });
37
38 it('serializes', function () {
39 const p = new PathParameter(':foo');
40 const result = JSON.stringify(p);
41 assert.strictEqual(result, '":foo"');
42 });
43
44 it('parameters are immutable', function () {
45 const p = new PathParameter('foo');
46 assert.throws(() => p.parameter = 'bar', TypeError);
47 });
48
49 }); // PathParameter