@@ -74,14 +74,25 @@ export interface RouterMockOptions extends Partial<RouterOptions> {
74
74
* START_LOCATION.
75
75
*/
76
76
initialLocation ?: RouteLocationRaw
77
+
77
78
/**
78
79
* Run in-component guards. Defaults to false
79
80
*/
80
81
runInComponentGuards ?: boolean
82
+
81
83
/**
82
84
* Run per-route guards. Defaults to false
83
85
*/
84
86
runPerRouteGuards ?: boolean
87
+
88
+ /**
89
+ * By default the mock will allow you to push to locations without adding all
90
+ * the necessary routes so you can still check if `router.push()` was called
91
+ * in a specific scenario
92
+ * (https://github.com/posva/vue-router-mock/issues/41). Set this to `true` to
93
+ * disable that behavior and throw when `router.push()` fails.
94
+ */
95
+ noUndeclaredRoutes ?: boolean
85
96
}
86
97
87
98
/**
@@ -101,7 +112,7 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
101
112
...options ,
102
113
} )
103
114
104
- let { runPerRouteGuards, runInComponentGuards } = options
115
+ let { runPerRouteGuards, runInComponentGuards, noUndeclaredRoutes } = options
105
116
const initialLocation = options . initialLocation || START_LOCATION
106
117
107
118
const { push, addRoute, replace } = router
@@ -197,7 +208,11 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
197
208
try {
198
209
// NOTE: should we trigger a push to reset the internal pending navigation of the router?
199
210
router . currentRoute . value = router . resolve ( to )
200
- } catch ( e ) { }
211
+ } catch ( error ) {
212
+ if ( noUndeclaredRoutes ) {
213
+ throw error
214
+ }
215
+ }
201
216
return Promise . resolve ( )
202
217
}
203
218
0 commit comments