Skip to content

Commit 87c5689

Browse files
committed
feat: reset onError
1 parent 6f001f4 commit 87c5689

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

__tests__/navigations.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Navigations', () => {
1515
})
1616

1717
it.todo('removes guards on reset()')
18+
it.todo('removes onError on reset()')
1819

1920
it('can check calls on push even if the route is not declared', async () => {
2021
const wrapper = mount(Test)

src/router.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
172172
} = options
173173
const initialLocation = options.initialLocation || START_LOCATION
174174

175-
const { push, addRoute, replace, beforeEach, beforeResolve } = router
175+
const { push, addRoute, replace, beforeEach, beforeResolve, onError } = router
176176

177177
const [addRouteMock, addRouteMockClear] = createSpy(
178178
(
@@ -216,6 +216,12 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
216216
guardRemovers.push(removeGuard)
217217
return removeGuard
218218
}
219+
let onErrorRemovers: Array<() => void> = []
220+
router.onError = (...args) => {
221+
const removeOnError = onError(...args)
222+
onErrorRemovers.push(removeOnError)
223+
return removeOnError
224+
}
219225

220226
function reset() {
221227
pushMockClear()
@@ -225,6 +231,9 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
225231
guardRemovers.forEach((remove) => remove())
226232
guardRemovers = []
227233

234+
onErrorRemovers.forEach((remove) => remove())
235+
onErrorRemovers = []
236+
228237
nextReturn = undefined
229238
router.currentRoute.value =
230239
initialLocation === START_LOCATION

0 commit comments

Comments
 (0)