Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Aug 14, 2024
1 parent 8325afd commit 55e3133
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 2 additions & 5 deletions app/assets/tests/composables/register.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
28 changes: 28 additions & 0 deletions app/assets/tests/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 55e3133

Please sign in to comment.