Skip to content

Commit

Permalink
feat: reset onError
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 8, 2024
1 parent 6f001f4 commit 87c5689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/navigations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('Navigations', () => {
})

it.todo('removes guards on reset()')
it.todo('removes onError on reset()')

it('can check calls on push even if the route is not declared', async () => {
const wrapper = mount(Test)
Expand Down
11 changes: 10 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
} = options
const initialLocation = options.initialLocation || START_LOCATION

const { push, addRoute, replace, beforeEach, beforeResolve } = router
const { push, addRoute, replace, beforeEach, beforeResolve, onError } = router

const [addRouteMock, addRouteMockClear] = createSpy(
(
Expand Down Expand Up @@ -216,6 +216,12 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock {
guardRemovers.push(removeGuard)
return removeGuard
}
let onErrorRemovers: Array<() => void> = []
router.onError = (...args) => {
const removeOnError = onError(...args)
onErrorRemovers.push(removeOnError)
return removeOnError
}

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

onErrorRemovers.forEach((remove) => remove())
onErrorRemovers = []

nextReturn = undefined
router.currentRoute.value =
initialLocation === START_LOCATION
Expand Down

0 comments on commit 87c5689

Please sign in to comment.