]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(matcher): check score is always different
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 Jul 2019 09:14:24 +0000 (11:14 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 Jul 2019 11:42:36 +0000 (13:42 +0200)
__tests__/matcher-ranking.spec.js

index 30f5799e25165d37dfb400280d73d4000215adc7..7d0cb5a137c2eef87831dd704b79a6b3ee6dee82 100644 (file)
@@ -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', () => {