Added tests for vuetify plugin
This commit is contained in:
parent
8129aaf0ad
commit
4f52f171d3
2 changed files with 111 additions and 9 deletions
97
tests/plugins/vuetify.spec.ts
Normal file
97
tests/plugins/vuetify.spec.ts
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
|
import { createVuetify } from "vuetify";
|
||||||
|
import * as components from "vuetify/components";
|
||||||
|
import * as directives from "vuetify/directives";
|
||||||
|
|
||||||
|
// Mock the CSS imports since they're not needed for testing
|
||||||
|
vi.mock("@mdi/font/css/materialdesignicons.css", () => ({}));
|
||||||
|
vi.mock("vuetify/styles", () => ({}));
|
||||||
|
|
||||||
|
// Mock createVuetify to spy on its calls
|
||||||
|
vi.mock("vuetify", () => ({
|
||||||
|
createVuetify: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock the components and directives
|
||||||
|
vi.mock("vuetify/components", () => ({
|
||||||
|
VApp: {},
|
||||||
|
VBtn: {},
|
||||||
|
// Add other components as needed for your tests
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("vuetify/directives", () => ({
|
||||||
|
vRipple: {},
|
||||||
|
vTooltip: {},
|
||||||
|
// Add other directives as needed for your tests
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("Vuetify Plugin Configuration", () => {
|
||||||
|
const mockVuetifyInstance = {
|
||||||
|
theme: {
|
||||||
|
current: { value: { dark: true } },
|
||||||
|
global: { name: { value: "dark" } },
|
||||||
|
},
|
||||||
|
defaults: {},
|
||||||
|
display: {},
|
||||||
|
locale: {},
|
||||||
|
rtl: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
(createVuetify as any).mockReturnValue(mockVuetifyInstance);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create vuetify instance with correct configuration", async () => {
|
||||||
|
// Import the module to trigger the createVuetify call
|
||||||
|
await import("../../src/plugins/vuetify");
|
||||||
|
|
||||||
|
expect(createVuetify).toHaveBeenCalledTimes(1);
|
||||||
|
expect(createVuetify).toHaveBeenCalledWith({
|
||||||
|
components,
|
||||||
|
directives,
|
||||||
|
theme: {
|
||||||
|
defaultTheme: "dark",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const callArgs = (createVuetify as any).mock.calls[0][0];
|
||||||
|
expect(callArgs.theme).toBeDefined();
|
||||||
|
expect(callArgs.theme.defaultTheme).toBe("dark");
|
||||||
|
expect(callArgs.components).toBe(components);
|
||||||
|
expect(callArgs.directives).toBe(directives);
|
||||||
|
|
||||||
|
const expectedKeys = ["components", "directives", "theme"];
|
||||||
|
const actualKeys = Object.keys(callArgs);
|
||||||
|
expect(actualKeys.sort()).toEqual(expectedKeys.sort());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should export the vuetify instance", async () => {
|
||||||
|
const vuetifyModule = await import("../../src/plugins/vuetify");
|
||||||
|
expect(vuetifyModule.default).toBeDefined();
|
||||||
|
expect(vuetifyModule.default).toBe(mockVuetifyInstance);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have proper module structure", () => {
|
||||||
|
// Test that the required dependencies are properly structured
|
||||||
|
expect(components).toBeDefined();
|
||||||
|
expect(directives).toBeDefined();
|
||||||
|
expect(typeof createVuetify).toBe("function");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("CSS imports", () => {
|
||||||
|
it("should import Material Design Icons CSS", () => {
|
||||||
|
// Since we're mocking the CSS import, we just verify it doesn't throw
|
||||||
|
expect(() => {
|
||||||
|
require("@mdi/font/css/materialdesignicons.css");
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should import Vuetify styles", () => {
|
||||||
|
// Since we're mocking the CSS import, we just verify it doesn't throw
|
||||||
|
expect(() => {
|
||||||
|
require("vuetify/styles");
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from "node:url";
|
||||||
import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
|
import { mergeConfig, defineConfig, configDefaults } from "vitest/config";
|
||||||
import viteConfig from './vite.config'
|
import viteConfig from "./vite.config";
|
||||||
|
|
||||||
export default mergeConfig(
|
export default mergeConfig(
|
||||||
viteConfig,
|
viteConfig,
|
||||||
defineConfig({
|
defineConfig({
|
||||||
test: {
|
test: {
|
||||||
environment: 'jsdom',
|
environment: "jsdom",
|
||||||
exclude: [...configDefaults.exclude, 'e2e/**'],
|
exclude: [...configDefaults.exclude, "e2e/**"],
|
||||||
root: fileURLToPath(new URL('./', import.meta.url)),
|
root: fileURLToPath(new URL("./", import.meta.url)),
|
||||||
coverage: {
|
coverage: {
|
||||||
reporter: ['text', 'lcov']
|
reporter: ["text", "lcov"],
|
||||||
}
|
},
|
||||||
|
server: {
|
||||||
|
deps: {
|
||||||
|
inline: ["vuetify"],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue