]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add __TEST__
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 3 May 2021 15:58:01 +0000 (17:58 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 3 May 2021 15:58:01 +0000 (17:58 +0200)
jest.config.js
rollup.config.js
src/global.d.ts
src/history/memory.ts

index dfc9f3afeca3e8a6408d27970b01d6dde9853694..549933e2d0540e416451632bbb5f9713df74b057 100644 (file)
@@ -2,6 +2,7 @@ module.exports = {
   testEnvironment: 'node',
   globals: {
     __DEV__: true,
+    __TEST__: true,
     __BROWSER__: true,
   },
   coverageDirectory: 'coverage',
index 2bb6b7ec3b11b8b1d244998c629d84f8e4ff8cb5..32fdf84ca7d6ef21207818ef7cb998b96f5f9576 100644 (file)
@@ -147,7 +147,7 @@ function createReplacePlugin(
       : // hard coded dev/prod builds
         JSON.stringify(!isProduction),
     // this is only used during tests
-    __TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : 'false',
+    __TEST__: 'false',
     // If the build is expected to run directly in the browser (global / esm builds)
     __BROWSER__: isBrowserBuild,
     __FEATURE_PROD_DEVTOOLS__: isBundlerESMBuild
index e348e51e212762ba6b95c7cc33753f9e381b7ff8..bb649e5a0b3de4dc138d5c466a77299f580dee58 100644 (file)
@@ -1,5 +1,6 @@
 // Global compile-time constants
 declare var __DEV__: boolean
+declare var __TEST__: boolean
 declare var __FEATURE_PROD_DEVTOOLS__: boolean
 declare var __BROWSER__: boolean
 declare var __CI__: boolean
index 5a021fbbcf96d985eecdc7789d7366522fbd56c7..5d3684f9fa5e755cacaefcdcd5459668c2d8f659 100644 (file)
@@ -102,5 +102,17 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
     get: () => queue[position],
   })
 
+  if (__TEST__) {
+    // @ts-ignore: only for tests
+    routerHistory.changeURL = function (url: string) {
+      const from = this.location
+      queue.splice(position++ + 1, queue.length, url)
+      triggerListeners(this.location, from, {
+        direction: NavigationDirection.unknown,
+        delta: 0,
+      })
+    }
+  }
+
   return routerHistory
 }