Skip to content

Commit

Permalink
add integration test for vuetify plugin, remove setup scripts from co…
Browse files Browse the repository at this point in the history
…verage
  • Loading branch information
MarvinOehlerkingCap committed Aug 5, 2024
1 parent d5c20c2 commit e08c515
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const config = deepmerge(defaultPreset, {

// Exclude
"!<rootDir>/src/**/index.(js|ts)",
"!<rootDir>/src/plugins/vuetify.ts",
],
});

Expand Down
5 changes: 4 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ sonar.organization=schulcloud-verbund
sonar.projectKey=hpi-schul-cloud_shd-client

sonar.sources=.
sonar.tests=src/
sonar.tests=.

# Exclude test files, locales and generated code from source scope
sonar.exclusions=src/serverApi/**/*,**/locales/**.ts

# Exclude scripts from root folder, app setup scripts from src and route config from coverage
sonar.coverage.exclusions=./*,src/*,src/router/*

# Include test files and test utils in test scope
sonar.test.inclusions=tests/**/*,**/*.unit.ts,**/*.unit.js

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/plugins/vuetify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "vuetify/styles";
import { createVuetify } from "vuetify";

import theme from "@/vuetify.options";
import theme from "./vuetify.options";

export default createVuetify({
...theme,
Expand Down
41 changes: 41 additions & 0 deletions src/plugins/vuetify.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { mount } from "@vue/test-utils";
import { defineComponent } from "vue";
import { VBtn } from "vuetify/lib/components/index.mjs";
import vuetify from "./vuetify";

jest.mock("vuetify/styles", () => ({}), { virtual: true });
jest.mock(
"vuetify/iconsets/mdi-svg",
() => ({
aliases: [],
mdi: [],
}),
{ virtual: true }
);

describe("vuetify plugin", () => {
describe("when creating the vuetify plugin", () => {
const setup = () => {
const TestComponent = defineComponent({
template: "<VBtn></VBtn>",
components: { VBtn },
});

const wrapper = mount(TestComponent, {
global: { plugins: [vuetify] },
});

return {
wrapper,
};
};

it("should make vuetify components available", () => {
const { wrapper } = setup();

const button = wrapper.findComponent(VBtn);

expect(button.exists()).toEqual(true);
});
});
});
20 changes: 20 additions & 0 deletions tests/test-utils/mountComposable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ComponentMountingOptions, mount } from "@vue/test-utils";
import { DefineComponent, defineComponent } from "vue";

export const mountComposable = <T>(
composable: () => T,
options?: ComponentMountingOptions<DefineComponent>
): T => {
const TestComponent = defineComponent({
setup() {
const result = composable();
return { result };
},
template: "<div></div>",
});

const wrapper = mount(TestComponent, options);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return wrapper.vm.result;
};

0 comments on commit e08c515

Please sign in to comment.