From 49c87ae7c5a6e2a9ad131b8cdce71bc7e479123c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 16 Mar 2020 10:09:53 +0100 Subject: [PATCH] test: refactor spies --- __tests__/router.spec.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index fde357b2..7f4a6f9a 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -131,24 +131,25 @@ describe('Router', () => { ) }) - // FIXME: - it.skip('navigates if the location does not exist', async () => { + it('navigates if the location does not exist', async () => { const { router } = await newRouter() const spy = jest.fn((to, from, next) => next()) router.beforeEach(spy) await router.push('/idontexist') - spy.mockReset() + expect(spy).toHaveBeenCalled() + expect(router.currentRoute.value).toMatchObject({ matched: [] }) + spy.mockClear() await router.push('/me-neither') - expect(spy).not.toHaveBeenCalled() + expect(router.currentRoute.value).toMatchObject({ matched: [] }) + expect(spy).toHaveBeenCalled() }) describe('alias', () => { it('does not navigate to alias if already on original record', async () => { const { router } = await newRouter() const spy = jest.fn((to, from, next) => next()) - router.beforeEach(spy) await router.push('/basic') - spy.mockReset() + router.beforeEach(spy) await router.push('/basic-alias') expect(spy).not.toHaveBeenCalled() }) @@ -156,9 +157,8 @@ describe('Router', () => { it('does not navigate to alias with children if already on original record', async () => { const { router } = await newRouter() const spy = jest.fn((to, from, next) => next()) - router.beforeEach(spy) await router.push('/aliases') - spy.mockReset() + router.beforeEach(spy) await router.push('/aliases1') expect(spy).not.toHaveBeenCalled() await router.push('/aliases2') @@ -168,9 +168,8 @@ describe('Router', () => { it('does not navigate to child alias if already on original record', async () => { const { router } = await newRouter() const spy = jest.fn((to, from, next) => next()) - router.beforeEach(spy) await router.push('/aliases/one') - spy.mockReset() + router.beforeEach(spy) await router.push('/aliases1/one') expect(spy).not.toHaveBeenCalled() await router.push('/aliases2/one') -- 2.47.3