Unit tests

This commit is contained in:
Joan Sanchez 2022-03-25 10:44:11 +01:00
parent 3683502f30
commit 1af0a3db31
3 changed files with 13 additions and 5 deletions

View File

@ -29,7 +29,7 @@ module.exports = {
// statements: 50
},
},
testMatch: ['<rootDir>/test/jest/__tests__/**/*.(spec|test).js', '<rootDir>/src/**/*.jest.(spec|test).js'],
testMatch: ['<rootDir>/src/**/__tests__/*.(spec|test).+(ts|js)?(x)'],
moduleFileExtensions: ['vue', 'js', 'jsx', 'json'],
moduleNameMapper: {
'^quasar$': 'quasar/dist/quasar.esm.prod.js',

View File

@ -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,
}),
}));

View File

@ -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 () => {