From 55d4781dde295039fd48e74f82edd92a4db34461 Mon Sep 17 00:00:00 2001 From: Liviu Burcusel Date: Sat, 13 Sep 2025 12:05:16 +0200 Subject: [PATCH] Added test for main.ts --- tests/main.spec.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/main.spec.ts diff --git a/tests/main.spec.ts b/tests/main.spec.ts new file mode 100644 index 0000000..17e2595 --- /dev/null +++ b/tests/main.spec.ts @@ -0,0 +1,52 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { createApp } from 'vue'; +import App from '../src/App.vue'; +import vuetify from '../src/plugins/vuetify'; +import router from '../src/router'; + +vi.mock('vue', async () => { + const actual = await vi.importActual('vue'); + return { + ...actual, + createApp: vi.fn(), + }; +}); + +vi.mock('./assets/main.css', () => ({})); + +vi.mock('./plugins/vuetify', () => ({ + default: { + install: vi.fn(), + }, +})); + +vi.mock('./router', () => ({ + default: { + install: vi.fn(), + }, +})); + +describe('main.ts', () => { + beforeEach(() => { + document.body.innerHTML = '
'; + vi.mocked(createApp).mockImplementation(() => ({ + use: vi.fn(), + mount: vi.fn(), + })); + }); + + it('creates app and uses plugins', async () => { + await import("../src/main"); + + expect(createApp).toHaveBeenCalledTimes(1); + expect(createApp).toHaveBeenCalledWith(App); + + const appMock = vi.mocked(createApp).mock.results[0].value; + expect(appMock.use).toHaveBeenCalledTimes(2); + expect(appMock.use).toHaveBeenCalledWith(vuetify); + expect(appMock.use).toHaveBeenCalledWith(router); + + expect(appMock.mount).toHaveBeenCalledTimes(1); + expect(appMock.mount).toHaveBeenCalledWith('#app'); + }); +});