From: Eduardo San Martin Morote Date: Mon, 16 Mar 2020 09:09:53 +0000 (+0100) Subject: test: refactor spies X-Git-Tag: v4.0.0-alpha.4~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49c87ae7c5a6e2a9ad131b8cdce71bc7e479123c;p=thirdparty%2Fvuejs%2Frouter.git test: refactor spies --- 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')