From 1af0a3db31b071b745eaa81afda3da3f75679604 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 25 Mar 2022 10:44:11 +0100 Subject: [PATCH] Unit tests --- jest.config.js | 2 +- src/components/__tests__/UserPanel.spec.js | 4 ++-- src/pages/Login/__tests__/Login.spec.js | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/jest.config.js b/jest.config.js index 932db7bb9..e18a46123 100755 --- a/jest.config.js +++ b/jest.config.js @@ -29,7 +29,7 @@ module.exports = { // statements: 50 }, }, - testMatch: ['/test/jest/__tests__/**/*.(spec|test).js', '/src/**/*.jest.(spec|test).js'], + testMatch: ['/src/**/__tests__/*.(spec|test).+(ts|js)?(x)'], moduleFileExtensions: ['vue', 'js', 'jsx', 'json'], moduleNameMapper: { '^quasar$': 'quasar/dist/quasar.esm.prod.js', diff --git a/src/components/__tests__/UserPanel.spec.js b/src/components/__tests__/UserPanel.spec.js index de2962985..1640a3a0e 100644 --- a/src/components/__tests__/UserPanel.spec.js +++ b/src/components/__tests__/UserPanel.spec.js @@ -6,11 +6,11 @@ import UserPanel from '../UserPanel.vue'; // Specify here Quasar config you'll need to test your component installQuasarPlugin(); -const routerPushMock = jest.fn(); +const mockPush = jest.fn(); jest.mock('vue-router', () => ({ useRouter: () => ({ - push: routerPushMock, + push: mockPush, }), })); diff --git a/src/pages/Login/__tests__/Login.spec.js b/src/pages/Login/__tests__/Login.spec.js index 7baf937d7..58db6eb15 100644 --- a/src/pages/Login/__tests__/Login.spec.js +++ b/src/pages/Login/__tests__/Login.spec.js @@ -12,14 +12,22 @@ installQuasarPlugin({ Notify } }); -const routerPushMock = jest.fn(); + +// https://stackoverflow.com/questions/68763693/vue-routers-injection-fails-during-a-jest-unit-test +const mockPush = jest.fn(); +const mockT = jest.fn(); jest.mock('vue-router', () => ({ useRouter: () => ({ - push: routerPushMock, + push: mockPush, }), })); +jest.mock('vue-i18n', () => ({ + useI18n: () => ({ + t: mockT + }), +})); describe('Login', () => { it('should successfully set the token into session', async () => {