|
|
@@ -1,57 +0,0 @@
|
|
|
-# Tests unitaires
|
|
|
-
|
|
|
-Ce répertoire contient les tests unitaires du front Vue.js
|
|
|
-
|
|
|
-> Plus d'infos:
|
|
|
->
|
|
|
-> * https://vuejs.org/guide/scaling-up/testing.html#unit-testing
|
|
|
-> * https://test-utils.vuejs.org/
|
|
|
-> * https://plugins.jetbrains.com/plugin/19220-vitest-runner
|
|
|
-
|
|
|
-## Exécuter les tests
|
|
|
-
|
|
|
-Pour exécuter les tests, lancer :
|
|
|
-
|
|
|
- yarn test
|
|
|
-
|
|
|
-## Mocking
|
|
|
-
|
|
|
-#### Différentes façons pour Mocker
|
|
|
-
|
|
|
- import axios from 'axios'
|
|
|
- import { NuxtAxiosInstance } from '@nuxtjs/axios'
|
|
|
- jest.mock('axios')
|
|
|
- const mockNuxtAxios = axios as jest.Mocked<NuxtAxiosInstance>
|
|
|
- mockNuxtAxios.$get = jest.fn().mockReturnValue({})
|
|
|
-
|
|
|
-Ou
|
|
|
-
|
|
|
- import DataProvider from "~/services/dataProvider/dataProvider";
|
|
|
- jest.mock('~/services/dataProvider/dataProvider');
|
|
|
- const DataProviderMock = DataProvider as jest.MockedClass<typeof DataProvider>;
|
|
|
- DataProviderMock.prototype.invoke.mockImplementation(async () => true)
|
|
|
-
|
|
|
-Ou
|
|
|
-
|
|
|
- import VueI18n from "vue-i18n";
|
|
|
- const VueI18nMock = VueI18n as jest.MockedClass<typeof VueI18n>;
|
|
|
- VueI18nMock.prototype.t = jest.fn().mockReturnValue('siret_error')
|
|
|
-
|
|
|
-Ou, si on définit le fichier ~/services/dataProvider/__mocks__/dataProvider.ts avec l'implémenation de invoke :
|
|
|
-
|
|
|
- const mock = jest.fn().mockImplementation(() => {
|
|
|
- return {invoke: () => {
|
|
|
- return true
|
|
|
- }};
|
|
|
- });
|
|
|
- export default mock;
|
|
|
-
|
|
|
-Alors on appelle useHandleSiret comme cela :
|
|
|
-
|
|
|
- const siretResponse = UseChecker.useHandleSiret(new DataProviderMock())
|
|
|
-
|
|
|
-
|
|
|
-ATTENTION : dans ce cas cette déclaration sera prioritaire sur les autres façons de mocker l'implémentation et on ne peut pas avoir 2 types de mock différents pour
|
|
|
-cette classe dans l'application.
|
|
|
-
|
|
|
-Pour pouvoir gérer l'implémentation à la volée, il ne faut pas qu'il y ait le fichier dans le dossier __mocks__
|