0👍
It looks like you’re using the component options definition instead of the component instance in your tests.
You should be creating a wrapper by mounting the component, and then you could access the component method via wrapper.vm
:
import { shallowMount } from '@vue/test-utils'
import FileToTest from '@/components/FileToTest.vue'
describe('FileToTest', () => {
it('exampleOfFunction returns false by default', () => {
const wrapper = shallowMount(FileToTest)
expect(wrapper.vm.exampleOfFunction()).toBe(false)
})
it('exampleOfFunction returns true when data is not 100', () => {
const wrapper = shallowMount(FileToTest)
wrapper.setData({ exampleOfData2: 0 })
expect(wrapper.vm.exampleOfFunction()).toBe(true)
})
})
- [Vuejs]-Problems with reactivity and computed properties Vue 3 – Composition API
- [Vuejs]-Close modal by using back button with hash route
Source:stackexchange.com