I'm trying to create a basic test for a function in Vue component and failing miserably.
main.ts
new Vue({
render: (h) => h(App),
router,
store,
}).$mount('#app')
App.ts
const App = Vue.extend({
components: { MainContainer },
data() {
return {
msg: 'Test',
}
},
name: 'App',
template: `<MainContainer />`,
})
export default App
MainContainer.vue
const MainContainer = Vue.extend({
components: {
Content,
},
methods: {
sum: (a: number, b: number): number => a + b,
},
})
export default MainContainer
MainContainer.spec.ts
import { createLocalVue, shallowMount } from '@vue/test-utils'
describe('MainComponent.vue', () => {
const localVue = createLocalVue()
test('sum method should add number together', () => {
const wrapper = shallowMount(MainContainer, { localVue })
expect(wrapper.vm.sum(1, 2)).toEqual(3)
})
Tests fails with the error
Property 'sum' does not exist on type 'CombinedVueInstance<Vue, object, object, object, Record<never, any>>'.
The same behavior I see if I try to test data.msg from App.ts. I'd appreciate any help. Thanks