diff --git a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/booleanProperty.test.ts b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/booleanProperty.test.ts index 26894c5c..3ae56dfc 100644 --- a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/booleanProperty.test.ts +++ b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/booleanProperty.test.ts @@ -1,4 +1,4 @@ -import {shallowMount} from '@vue/test-utils'; +import {mount} from '@vue/test-utils'; import {afterEach, beforeEach, describe, expect, it, test, vi} from 'vitest'; import BooleanProperty from '../BooleanProperty.vue'; import SelectButton from 'primevue/selectbutton'; @@ -21,10 +21,10 @@ describe('BooleanProperty', () => { let wrapper: any; let selectButton: any; - function shallowMountBeforeEach(props: any) { + function mountBeforeEach(props: any) { beforeEach(() => { // @ts-ignore - wrapper = shallowMount(BooleanProperty, { + wrapper = mount(BooleanProperty, { props: props, }); selectButton = wrapper.findComponent(SelectButton); @@ -39,7 +39,7 @@ describe('BooleanProperty', () => { ['false', false], ['undefined', undefined], ])(`with value %s`, (type, data) => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: data, validationResults: new ValidationResult([]), diff --git a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/enumProperty.test.ts b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/enumProperty.test.ts index 6e93a123..f00e0cf4 100644 --- a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/enumProperty.test.ts +++ b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/enumProperty.test.ts @@ -1,10 +1,17 @@ -import {shallowMount} from '@vue/test-utils'; +import {mount} from '@vue/test-utils'; import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; import EnumProperty from '@/components/panels/gui-editor/properties/EnumProperty.vue'; import Select from 'primevue/select'; import {ValidationResult} from '@/schema/validationService'; import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper'; import {SessionMode} from '@/store/sessionMode'; +import { config } from '@vue/test-utils'; +import { defaultOptions } from 'primevue/config'; + + +config.global.mocks['$primevue'] = { + config: defaultOptions +}; // avoid constructing useDataLink store through imports, it is not required for this component vi.mock('@/data/useDataLink', () => ({ @@ -25,10 +32,10 @@ describe('EnumProperty', () => { let wrapper: any; let dropdown: any; - function shallowMountBeforeEach(props: any) { + function mountBeforeEach(props: any) { beforeEach(() => { // @ts-ignore - wrapper = shallowMount(EnumProperty, { + wrapper = mount(EnumProperty, { props: props, }); dropdown = wrapper.findComponent(Select); @@ -52,7 +59,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(stringValuesProps); + mountBeforeEach(stringValuesProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(stringValuesProps); @@ -128,7 +135,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(numberValuesProps); + mountBeforeEach(numberValuesProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(numberValuesProps); @@ -183,7 +190,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(booleanValuesProps); + mountBeforeEach(booleanValuesProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(booleanValuesProps); @@ -238,7 +245,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(objectValuesProps); + mountBeforeEach(objectValuesProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(objectValuesProps); @@ -296,7 +303,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(arrayValuesProps); + mountBeforeEach(arrayValuesProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(arrayValuesProps); @@ -353,7 +360,7 @@ describe('EnumProperty', () => { beforeEach(() => { // @ts-ignore - wrapper = shallowMount(EnumProperty, { + wrapper = mount(EnumProperty, { props: nullValuesProps, }); dropdown = wrapper.findComponent(Select); @@ -403,7 +410,7 @@ describe('EnumProperty', () => { false ), }; - shallowMountBeforeEach(testProps); + mountBeforeEach(testProps); it('should have the correct props', () => { expect(wrapper.props()).toEqual(testProps); diff --git a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/numberProperty.test.ts b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/numberProperty.test.ts index 70eeda2b..130659de 100644 --- a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/numberProperty.test.ts +++ b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/numberProperty.test.ts @@ -1,4 +1,4 @@ -import {shallowMount} from '@vue/test-utils'; +import {mount} from '@vue/test-utils'; import {afterEach, beforeEach, describe, expect, it, test, vi} from 'vitest'; import NumberProperty from '../NumberProperty.vue'; import InputNumber from 'primevue/inputnumber'; @@ -6,6 +6,13 @@ import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper'; import {GuiConstants} from '@/constants'; import {SessionMode} from '@/store/sessionMode'; import {ValidationResult} from '@/schema/validationService'; +import { config } from '@vue/test-utils'; +import { defaultOptions } from 'primevue/config'; + + +config.global.mocks['$primevue'] = { + config: defaultOptions +}; // avoid constructing useDataLink store through imports, it is not required for this component vi.mock('@/data/useDataLink', () => ({ @@ -22,10 +29,10 @@ describe('NumberProperty', () => { let wrapper: any; let inputNumber: any; - function shallowMountBeforeEach(props: any) { + function mountBeforeEach(props: any) { beforeEach(() => { // @ts-ignore - wrapper = shallowMount(NumberProperty, { + wrapper = mount(NumberProperty, { props: props, }); inputNumber = wrapper.findComponent(InputNumber); @@ -49,10 +56,10 @@ describe('NumberProperty', () => { false ), }; - shallowMountBeforeEach(props); + mountBeforeEach(props); it('should correctly setup the input number', () => { - expect(inputNumber.props().modelValue).toBe(data ?? null); // primeVue converts undefined to null + expect(inputNumber.props().modelValue).toBe(data); expect(inputNumber.props().minFractionDigits).toBe(0); expect(inputNumber.props().maxFractionDigits).toBe(0); expect(inputNumber.props().step).toBe(1); @@ -79,10 +86,10 @@ describe('NumberProperty', () => { false ), }; - shallowMountBeforeEach(props); + mountBeforeEach(props); it('should correctly setup the input number', () => { - expect(inputNumber.props().modelValue).toBe(data ?? null); // primeVue converts undefined to null + expect(inputNumber.props().modelValue).toBe(data); expect(inputNumber.props().minFractionDigits).toBe(0); expect(inputNumber.props().maxFractionDigits).toBe(GuiConstants.NUMBER_MAX_DECIMAL_PLACES); expect(inputNumber.props().step).toBe(0.5); @@ -95,7 +102,7 @@ describe('NumberProperty', () => { }); describe('emits the correct event', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: 1, validationResults: new ValidationResult([]), diff --git a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/stringProperty.test.ts b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/stringProperty.test.ts index 461c0787..e9825edb 100644 --- a/meta_configurator/src/components/panels/gui-editor/properties/__tests__/stringProperty.test.ts +++ b/meta_configurator/src/components/panels/gui-editor/properties/__tests__/stringProperty.test.ts @@ -1,10 +1,17 @@ -import {shallowMount} from '@vue/test-utils'; +import {mount} from '@vue/test-utils'; import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; import StringProperty from '../StringProperty.vue'; import InputText from 'primevue/inputtext'; import {ValidationResult} from '@/schema/validationService'; import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper'; import {SessionMode} from '@/store/sessionMode'; +import { config } from '@vue/test-utils'; +import { defaultOptions } from 'primevue/config'; + + +config.global.mocks['$primevue'] = { + config: defaultOptions +}; // avoid constructing useDataLink store through imports, it is not required for this component vi.mock('@/data/useDataLink', () => ({ @@ -21,10 +28,10 @@ describe('StringProperty', () => { let wrapper: any; let inputField: any; - function shallowMountBeforeEach(props: any) { + function mountBeforeEach(props: any) { beforeEach(() => { // @ts-ignore - wrapper = shallowMount(StringProperty, { + wrapper = mount(StringProperty, { props: props, }); inputField = wrapper.findComponent(InputText); @@ -35,7 +42,7 @@ describe('StringProperty', () => { } describe('with string data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: 'bar', validationResults: new ValidationResult([]), @@ -93,7 +100,7 @@ describe('StringProperty', () => { }); describe('with number data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: 1, validationResults: new ValidationResult([]), @@ -112,7 +119,7 @@ describe('StringProperty', () => { }); describe('with object data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: {}, validationResults: new ValidationResult([]), @@ -131,7 +138,7 @@ describe('StringProperty', () => { }); describe('with array data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: [], validationResults: new ValidationResult([]), @@ -150,7 +157,7 @@ describe('StringProperty', () => { }); describe('with null data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: null, validationResults: new ValidationResult([]), @@ -169,7 +176,7 @@ describe('StringProperty', () => { }); describe('with undefined data', () => { - shallowMountBeforeEach({ + mountBeforeEach({ propertyName: 'foo', propertyData: undefined, validationResults: new ValidationResult([]), diff --git a/meta_configurator/vitest.config.ts b/meta_configurator/vitest.config.ts index 1252a90c..17b42fdd 100644 --- a/meta_configurator/vitest.config.ts +++ b/meta_configurator/vitest.config.ts @@ -2,20 +2,28 @@ import {fileURLToPath, URL} from 'node:url'; import {mergeConfig} from 'vite'; import {configDefaults, defineConfig} from 'vitest/config'; import viteConfig from './vite.config'; +import {config} from '@vue/test-utils'; +import PrimeVue from 'primevue/config'; +import {UserConfig} from "vitest"; + + + + +const userConfig: UserConfig = defineConfig({ + test: { + environment: 'jsdom', + exclude: [...configDefaults.exclude, 'e2e/*'], + root: fileURLToPath(new URL('./', import.meta.url)), + transformMode: { + web: [/\.[jt]sx$/], + }, + coverage: { + provider: 'c8', + }, + }, +}); export default mergeConfig( viteConfig, - defineConfig({ - test: { - environment: 'jsdom', - exclude: [...configDefaults.exclude, 'e2e/*'], - root: fileURLToPath(new URL('./', import.meta.url)), - transformMode: { - web: [/\.[jt]sx$/], - }, - coverage: { - provider: 'c8', - }, - }, - }) + userConfig, );