From 988c47677b8287f9591e0be543b9b20cb957f35f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 17:01:11 +0100 Subject: [PATCH] refs #6384 test: fix vitest --- .../components/common/VnSearchBar.spec.js | 45 ++++++------------- test/vitest/helper.js | 20 ++++++++- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnSearchBar.spec.js b/test/vitest/__tests__/components/common/VnSearchBar.spec.js index 24111e90e..fd0a026ef 100644 --- a/test/vitest/__tests__/components/common/VnSearchBar.spec.js +++ b/test/vitest/__tests__/components/common/VnSearchBar.spec.js @@ -2,36 +2,6 @@ import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vite import { createWrapper, axios } from 'app/test/vitest/helper'; import VnSearchbar from 'components/ui/VnSearchbar.vue'; -vi.mock('vue-router', () => ({ - useRouter: () => ({ - push: vi.fn( ), - currentRoute: { - value: { - params: { - id: 11, - }, - }, - }, - }), - useRoute: () => ({ - matched: [ - { - path: '/', - }, - { - path: '/customer', - }, - { - path: '/customer/:id', - }, - { - path: '/customer/:id/basic-data', - }, - ], - query: {}, - params: {}, - }), -})); describe('VnSearchBar', () => { let vm; @@ -46,7 +16,20 @@ describe('VnSearchBar', () => { }, }); vm = wrapper.vm; - + vm.route.matched = [ + { + path: '/', + }, + { + path: '/customer', + }, + { + path: '/customer/:id', + }, + { + path: '/customer/:id/basic-data', + }, + ]; }); afterEach(() => { diff --git a/test/vitest/helper.js b/test/vitest/helper.js index 2b8c70a5f..89cc640fd 100644 --- a/test/vitest/helper.js +++ b/test/vitest/helper.js @@ -14,6 +14,25 @@ installQuasarPlugin({ }, }); const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false }); +const mockPush = vi.fn(); + +vi.mock('vue-router', () => ({ + useRouter: () => ({ + push: mockPush, + currentRoute: { + value: { + params: { + id: 1, + }, + }, + }, + }), + useRoute: () => ({ + matched: [], + query: {}, + params: {}, + }), +})); vi.mock('axios'); @@ -55,7 +74,6 @@ export function createWrapper(component, options) { mocks: { t: (tKey) => tKey, $t: (tKey) => tKey, - customRouter: false }, };