I need to make a test for a method in a VUE3 setup in a component and nothing I have tried works.
Here is the simplified component:
<script setup>
function myFunction(number) {
return number + 1
}
</script>
<template>
// code here
And the test:
import { MyComponent } from '@/Components/MyComponent.vue'
import { describe, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
describe('MyComponent.vue', () => {
test('myMethodWorks', () => {
const wrapper = mount(MyComponent)
const result = wrapper.vm.$setupState.myFunction(1);
expect(result).toBe(2)
});
});
But I keep getting the error: ReferenceError: document is not defined. There are other tests in the Vue test folder that work fine, so I shouldn’t need to change any config files. But none of the other tests are trying to test a method from a Vue3 component.
Even if I put in the test :
expect(true).toBe(true)
I still get the same error.
What am I doing wrong?