From 6e7f877127ce2c52da3542c8142f9e5f35b372bc Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 18 Feb 2021 22:53:23 +0100 Subject: [PATCH] test: fix error spy --- __tests__/lazyLoading.spec.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/__tests__/lazyLoading.spec.ts b/__tests__/lazyLoading.spec.ts index 62a4c3b9..54bfffe8 100644 --- a/__tests__/lazyLoading.spec.ts +++ b/__tests__/lazyLoading.spec.ts @@ -26,6 +26,15 @@ function createLazyComponent() { describe('Lazy Loading', () => { mockWarn() + let consoleErrorSpy: jest.SpyInstance + beforeEach(() => { + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}) + }) + + afterEach(() => { + consoleErrorSpy.mockRestore() + }) + it('works', async () => { const { component, resolve } = createLazyComponent() const { router } = newRouter({ @@ -250,11 +259,12 @@ describe('Lazy Loading', () => { const spy = jest.fn() - reject(new Error('fail')) + const error = new Error('fail') + reject(error) await router.push('/foo').catch(spy) expect(spy).toHaveBeenCalled() - expect('fail').toHaveBeenWarned() + expect(console.error).toHaveBeenCalledWith(error) expect(router.currentRoute.value).toMatchObject({ path: '/', -- 2.39.5