Added test for main.ts
This commit is contained in:
parent
4f52f171d3
commit
55d4781dde
1 changed files with 52 additions and 0 deletions
52
tests/main.spec.ts
Normal file
52
tests/main.spec.ts
Normal file
|
|
@ -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 = '<div id="app"></div>';
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue