From 171c11aa380434b3f9059f83071ed3bcd49bb634 Mon Sep 17 00:00:00 2001 From: Scott Hardy Date: Sun, 4 Dec 2016 12:10:39 -0800 Subject: [PATCH] test(): add failing test for non-deterministic matching --- test/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/index.js b/test/index.js index 0d5b1ef..be071ff 100644 --- a/test/index.js +++ b/test/index.js @@ -276,4 +276,24 @@ describe('switchPath corner cases', () => { expect(path).to.be.equal('/') expect(value).to.be.equal('root') }) + + it('should deterministically match more specific path in case many match', () => { + (() => { + let {path, value} = switchPath('/home/specific', { + '/home/specific': 123, + '/home/:id': id => `id is ${id}` + }); + expect(path).to.be.equal('/home/specific'); + expect(value).to.be.equal(123); + })(); + + (() => { + let {path, value} = switchPath('/home/specific', { + '/home/:id': id => `id is ${id}`, + '/home/specific': 123 + }); + expect(path).to.be.equal('/home/specific'); + expect(value).to.be.equal(123); + })(); + }); });