I'm trying make a test for a variable, but I get undefined
when I try access the value:
Component where I defined the variable
setup(props, context) {
const name = ref('Josue');
return {
name,
}
}
Test
import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
import QBUTTON from './demo/QBtn-demo.vue'
import index from '../../../src/pages/Index.vue'
import * as All from 'quasar'
import compositionApi from '@vue/composition-api';
const localVue = createLocalVue()
localVue.use(compositionApi)
describe('Index', () => {
it('is a Vue instance',async () => {
const wrapper = mount(index, { localVue })
await wrapper.vm.$forceUpdate();
expect(wrapper.vm.$data.nombre).toBe('Josue')
})
})
Error
Expected: "Josue"
Received: undefined
116 | const wrapper = mount(index, { localVue })
117 | await wrapper.vm.$forceUpdate();
> 118 | expect(wrapper.vm.$data.nombre).toBe('Josue')
| ^
119 | })
120 | })
I got undefined
from wrapper.vm.$data.nombre
, but if I use:
data () {
return {
name: 'Josue',
}
},
...it works. I dont know how to access a variable when I use the Composition API.
Aucun commentaire:
Enregistrer un commentaire