X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Frouter%2Fpath-parameter.js;h=8761b663d50c3f166aa1c87f6a12871af40ce91f;hb=356f9a3b45d5b6bbcc310a2b37b6f59dfd76b923;hp=9b2fb1ed828f68f26ac9462f06f826a10d243f00;hpb=9fe1e9b22b8e753c44dec77d1dee3d0061b2e991;p=squeep-api-dingus diff --git a/test/lib/router/path-parameter.js b/test/lib/router/path-parameter.js index 9b2fb1e..8761b66 100644 --- a/test/lib/router/path-parameter.js +++ b/test/lib/router/path-parameter.js @@ -1,51 +1,49 @@ /* eslint-env mocha */ 'use strict'; -const assert = require('assert'); +const assert = require('node:assert'); const PathParameter = require('../../../lib/router/path-parameter'); -const noExpectedException = 'did not receive expected exception'; describe('PathParameter', function () { beforeEach(function () { PathParameter._flush(); }); + it('requires a parameter', function () { - try { - new PathParameter(); - assert.fail(noExpectedException); - } catch (e) { - assert(e instanceof RangeError, noExpectedException); - } + assert.throws(() => new PathParameter(), RangeError); }); + it('requires parameter be a string', function () { - try { - new PathParameter({}); - assert.fail(noExpectedException); - } catch (e) { - assert(e instanceof RangeError, noExpectedException); - } + assert.throws(() => new PathParameter({}), RangeError); }); + it('creates a parameter object', function () { const p = new PathParameter('foo'); assert(p instanceof PathParameter); assert.strictEqual(p.parameter, 'foo'); }); + it('duplicate parameters are the same object', function () { const p1 = new PathParameter('foo'); const p2 = new PathParameter('foo'); assert.strictEqual(p1, p2); + assert(Object.is(p1, p2)); }); + it('shows itself', function () { const p = new PathParameter('foo'); - assert(p.toString().includes('foo')); + assert.strictEqual(`${p}`, 'foo'); }); + + it('serializes', function () { + const p = new PathParameter(':foo'); + const result = JSON.stringify(p); + assert.strictEqual(result, '":foo"'); + }); + it('parameters are immutable', function () { const p = new PathParameter('foo'); - try { - p[PathParameter.kPathParameter] = 'bar'; - assert.fail(noExpectedException); - } catch (e) { - assert(e instanceof TypeError, noExpectedException); - } - }); -}); // PathParameter \ No newline at end of file + assert.throws(() => p.parameter = 'bar', TypeError); + }); + +}); // PathParameter