From: Eduardo San Martin Morote Date: Wed, 17 Jul 2019 09:14:24 +0000 (+0200) Subject: test(matcher): check score is always different X-Git-Tag: v4.0.0-alpha.0~297 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd0b61295e2df41014eda4339e39be380499ea5b;p=thirdparty%2Fvuejs%2Frouter.git test(matcher): check score is always different --- diff --git a/__tests__/matcher-ranking.spec.js b/__tests__/matcher-ranking.spec.js index 30f5799e..7d0cb5a1 100644 --- a/__tests__/matcher-ranking.spec.js +++ b/__tests__/matcher-ranking.spec.js @@ -39,8 +39,21 @@ describe('createRouteMatcher', () => { ) ) .sort((a, b) => b.score - a.score) - .map(matcher => matcher.record.path) - expect(matchers).toEqual(paths) + + expect(matchers.map(matcher => matcher.record.path)).toEqual(paths) + + // Fail if two consecutive records have the same record + for (let i = 1; i < matchers.length; i++) { + const a = matchers[i - 1] + const b = matchers[i] + try { + expect(a.score).not.toBe(b.score) + } catch (e) { + throw new Error( + `Record "${a.record.path}" and "${b.record.path}" have the same score: ${a.score}. Avoid putting routes with the same score on the same test` + ) + } + } } it('orders a rest param with root', () => {