Skip to content

Commit

Permalink
feat: add replace
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Nov 10, 2020
1 parent 20f5a19 commit 8ba4439
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion __tests__/navigations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ describe('Navigations', () => {
addGlobalInjections(router)
})

it('can check calls', async () => {
it('can check calls on push', async () => {
const wrapper = mount(Test)

wrapper.vm.$router.push('/hey')
expect(wrapper.vm.$router.push).toHaveBeenCalledWith('/hey')
expect(wrapper.vm.$router.push).toHaveBeenCalledTimes(1)
})

it('can check calls on replace', async () => {
const wrapper = mount(Test)

wrapper.vm.$router.replace('/hey')
expect(wrapper.vm.$router.replace).toHaveBeenCalledWith('/hey')
expect(wrapper.vm.$router.replace).toHaveBeenCalledTimes(1)
})

it('reset calls between tests', async () => {
const wrapper = mount(Test)
expect(wrapper.vm.$router.push).toHaveBeenCalledTimes(0)
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ export function createMockedRouter() {
return Promise.resolve()
})

const replaceMock = jest.fn((to) => {
router.currentRoute.value = router.resolve(to)
// resolve pending navigation failure
return Promise.resolve()
})

router.push = pushMock
router.replace = replaceMock

beforeEach(() => {
pushMock.mockClear()
replaceMock.mockClear()
})

// TODO: replace

return router
}

Expand Down

0 comments on commit 8ba4439

Please sign in to comment.