]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: better mocha snapshot matching
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 10:09:16 +0000 (12:09 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 10:09:16 +0000 (12:09 +0200)
__tests__/helper.js
__tests__/matcher.spec.js

index 9f46366f0e5af5e22e6580ac18baafa6e56f95f0..97c3ac1bd614c4c719ec28f0cd7d579718aff4b6 100644 (file)
@@ -6,15 +6,30 @@ if (typeof global !== 'undefined' && typeof global.beforeAll === 'undefined') {
   const mocks = require('jest-mock')
   global.jest = mocks
 
+  const INITIAL_WS_RE = /^\s+/
+
   const expect = require('expect')
   // monkey patch jest snapshots
   expect.extend({
     toMatchInlineSnapshot(received, snapshot) {
       const text = `[${received.toString()}]`
-      const pass = text === snapshot
+
+      const match = INITIAL_WS_RE.exec(snapshot)
+      let expected = snapshot
+      if (match) {
+        // remove the initial linefeed
+        const pad = match[0].replace(/^\n/, '')
+        expected = snapshot
+          .split('\n')
+          .map(chunk => chunk.slice(pad.length))
+          .join('\n')
+          .trim()
+      }
+      const pass = text === expected
       return {
         pass,
-        message: () => 'Snapshot not maching: ' + text,
+        message: () =>
+          `Snapshot not maching.\nExpected:\n${expected}\nReceived:\n${text}`,
       }
     },
   })
index 4a21698ec33ff6ad9516e24403b44a9bc6de2f53..f9209839cadd50358cf2a8157435228a4e2c3f16 100644 (file)
@@ -262,10 +262,6 @@ describe('Router Matcher', () => {
           return resolved
         }
 
-        // FIXME: refactor the tests into the function, probably use a common set of routes
-        // tests named routes and relatives routes
-        // move to different folder
-
         it('resolves a redirect string', () => {
           const records = [
             { path: '/home', component },