diff --git a/src/components/__tests__/create-form/BaseInput.spec.ts b/src/components/__tests__/create-form/BaseInput.spec.ts index dbbe24e3b7ebe8171096c7ff9a721accd5ff8bdd..abf5a6074f0bf92eac2d2965d6b2eaab8824b931 100644 --- a/src/components/__tests__/create-form/BaseInput.spec.ts +++ b/src/components/__tests__/create-form/BaseInput.spec.ts @@ -29,8 +29,13 @@ describe('BaseInput', () => { const newValue = 'New Value' await input.setValue(newValue) - // Assert emitted event - expect(wrapper.emitted()['update:modelValue']).toBeTruthy() - expect(wrapper.emitted()['update:modelValue'][0][0]).toBe(newValue) + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + + const updateModelValueEvents = emittedEvents['update:modelValue'] as any[] + expect(updateModelValueEvents).toBeTruthy() + + const newValueEmitted = updateModelValueEvents[0][0] + expect(newValueEmitted).toBe(newValue) }) }) diff --git a/src/components/__tests__/create-form/BaseTextArea.spec.ts b/src/components/__tests__/create-form/BaseTextArea.spec.ts index fbead7019eea9d0de1b23b330ea28366ae9a9836..07c9a5eb4069f8ae26a51f33d793817e8b6502b6 100644 --- a/src/components/__tests__/create-form/BaseTextArea.spec.ts +++ b/src/components/__tests__/create-form/BaseTextArea.spec.ts @@ -25,7 +25,13 @@ describe('BaseTextArea', () => { const newValue = 'New Value' await textarea.setValue(newValue) - expect(wrapper.emitted()['update:modelValue']).toBeTruthy() - expect(wrapper.emitted()['update:modelValue'][0][0]).toBe(newValue) + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + + const updateModelValueEvents = emittedEvents['update:modelValue'] as any[] + expect(updateModelValueEvents).toBeTruthy() + + const newValueEmitted = updateModelValueEvents[0][0] + expect(newValueEmitted).toBe(newValue) }) }) diff --git a/src/components/__tests__/economy/ToggleButton.spec.ts b/src/components/__tests__/economy/ToggleButton.spec.ts index e2addb1dfa62e3494ca1ec9f0f73f7728d429f76..30d04e0829a9996e2f97bf7210e427f2cfdded2e 100644 --- a/src/components/__tests__/economy/ToggleButton.spec.ts +++ b/src/components/__tests__/economy/ToggleButton.spec.ts @@ -4,25 +4,27 @@ import ToggleButton from '@/components/economy/ToggleButton.vue' describe('ToggleButton', () => { it('toggles chart visibility when clicked', async () => { - const wrapper = mount(ToggleButton) + + const wrapper = mount(ToggleButton) as any expect(wrapper.vm.chartVisible).toBe(false) await wrapper.find('input[type="checkbox"]').trigger('change') expect(wrapper.vm.chartVisible).toBe(true) - }) it('emits toggle-chart event when clicked', async () => { - const wrapper = mount(ToggleButton) - + const wrapper = mount(ToggleButton) as any // Simulate clicking the toggle button await wrapper.find('input[type="checkbox"]').trigger('change') - - expect(wrapper.emitted('toggle-chart')).toBeTruthy() + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + const toggleChartEmit = emittedEvents['toggle-chart'] as any[] // Type assertion to any[] + expect(toggleChartEmit).toBeTruthy() expect(wrapper.vm.chartVisible).toBe(true) await wrapper.find('input[type="checkbox"]').trigger('change') + expect(wrapper.emitted('toggle-chart')).toBeTruthy() - expect(wrapper.emitted('toggle-chart')[1][0]).toBe(false) + expect(toggleChartEmit[1][0]).toBe(false) }) }) diff --git a/src/components/__tests__/economy/TransactionComponent.spec.ts b/src/components/__tests__/economy/TransactionComponent.spec.ts index 2e9b91b2b87cc857b328d5e3ab0fb8c791bc5df3..9e21ac448ed0aa7e286dd56adc71d7ac38c0cab7 100644 --- a/src/components/__tests__/economy/TransactionComponent.spec.ts +++ b/src/components/__tests__/economy/TransactionComponent.spec.ts @@ -20,16 +20,44 @@ describe('TransactionComponent', () => { }) // title rendering - expect(wrapper.find('.component-title').text()).toContain(title) + const titleElement = wrapper.find('.component-title') + if (titleElement.exists()) { + expect(titleElement.text()).toContain(title) + } else { + throw new Error('Title element not found'); + } - // date rendering - expect(wrapper.findAll('.component-right-field').at(0).text()).toContain(date) + // Find all component-right-field elements + const rightFieldElements = wrapper.findAll('.component-right-field') - // amount rendering - expect(wrapper.findAll('.component-right-field').at(1).text()).toContain(`${amount}kr`) + // Check if elements exist and have expected text content + if (rightFieldElements.length >= 3) { + // date rendering + const dateElement = rightFieldElements.at(0) + if (dateElement) { + expect(dateElement.text()).toContain(date) + } else { + throw new Error('Date element not found'); + } + + // amount rendering + const amountElement = rightFieldElements.at(1) + if (amountElement) { + expect(amountElement.text()).toContain(`${amount}kr`) + } else { + throw new Error('Amount element not found'); + } - // category rendering - expect(wrapper.findAll('.component-right-field').at(2).text()).toContain(category) + // category rendering + const categoryElement = rightFieldElements.at(2) + if (categoryElement) { + expect(categoryElement.text()).toContain(category) + } else { + throw new Error('Category element not found'); + } + } else { + throw new Error('Expected elements not found'); + } }) }) diff --git a/src/components/__tests__/milestonePath/MilestoneButton.spec.ts b/src/components/__tests__/milestonePath/MilestoneButton.spec.ts index a8b488b1410fbc9df70625c7a1955f5e6a35cd1e..523f41f1da2808eab47f688a7d06dd81c7fc67cf 100644 --- a/src/components/__tests__/milestonePath/MilestoneButton.spec.ts +++ b/src/components/__tests__/milestonePath/MilestoneButton.spec.ts @@ -18,7 +18,7 @@ describe('MilestoneButton', () => { expect(wrapper.text()).toBe('Save') // button color - const buttonElement = wrapper.find('.save-button').element - expect(buttonElement.style.backgroundColor).toBe(buttonColor) + const buttonElement = wrapper.find('.save-button').element as HTMLElement + expect(buttonElement.style?.backgroundColor).toBe(buttonColor) }) })