From 55e3133e40731e20a94f0b7a3016a5e763b1be1c Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Tue, 13 Aug 2024 22:20:41 -0400 Subject: [PATCH] Add more tests --- app/assets/tests/composables/register.test.ts | 7 ++--- app/assets/tests/plugin.test.ts | 28 +++++++++++++++++++ vite.config.ts | 3 +- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 app/assets/tests/plugin.test.ts diff --git a/app/assets/tests/composables/register.test.ts b/app/assets/tests/composables/register.test.ts index 37a82be..32bc557 100644 --- a/app/assets/tests/composables/register.test.ts +++ b/app/assets/tests/composables/register.test.ts @@ -1,10 +1,7 @@ -import { setActivePinia, createPinia } from 'pinia' -import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' -import { useAuthStore } from '../../stores/auth' +import { afterEach, describe, expect, test, vi } from 'vitest' import axios from 'axios' -import type { LoginForm, UserInterface } from 'app/assets/interfaces' +import type { UserInterface } from 'app/assets/interfaces' import { AlertStyle } from '@userfrosting/sprinkle-core/types' -// import * as Config from '@userfrosting/sprinkle-core/stores' import { useConfigStore } from '@userfrosting/sprinkle-core/stores' import { Register } from '../../composables' diff --git a/app/assets/tests/plugin.test.ts b/app/assets/tests/plugin.test.ts new file mode 100644 index 0000000..1af6069 --- /dev/null +++ b/app/assets/tests/plugin.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, test, vi } from 'vitest' +import { createApp } from 'vue' +import { useAuthStore } from '../stores/auth' +import { useAuthGuard } from '../guards/authGuard' +import { useRouter } from 'vue-router' +import plugin from '../plugin' +import * as Auth from '../stores/auth' +import * as AuthGuard from '../guards/authGuard' + +const mockAuthStore = { + check: vi.fn() +} + +describe('Plugin', () => { + test('should install the plugin with the provided options', () => { + const app = createApp({}) + const router = useRouter() + + vi.spyOn(Auth, 'useAuthStore').mockReturnValue(mockAuthStore as any) + vi.spyOn(AuthGuard, 'useAuthGuard').mockReturnValue({} as any) + + plugin.install(app, { router }) + + expect(useAuthStore).toHaveBeenCalled() + expect(mockAuthStore.check).toHaveBeenCalled() + expect(useAuthGuard).toHaveBeenCalledWith(router) + }) +}) diff --git a/vite.config.ts b/vite.config.ts index 3fa1902..4adc5bd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -32,8 +32,9 @@ export default defineConfig({ }, test: { coverage: { + reportsDirectory: './_meta/_coverage', include: ['app/assets/**/*.*'], - reportsDirectory: './_meta/_coverage' + exclude: ['app/assets/tests/**/*.*', 'app/assets/interfaces/routes.ts'] }, environment: 'happy-dom' }