Vue.js Vue JS Jest:mount()不';渲染不好
MyView.vue:Vue.js Vue JS Jest:mount()不';渲染不好,vue.js,testing,jestjs,Vue.js,Testing,Jestjs,MyView.vue: <template> <v-container fluid> <v-row> <v-col v-for="obj in myObjs" :key="obj.ref"> <MyChild :obj="obj" /> </v-col> </v-row> </v-container> </template>
<template>
<v-container fluid>
<v-row>
<v-col v-for="obj in myObjs" :key="obj.ref">
<MyChild :obj="obj" />
</v-col>
</v-row>
</v-container>
</template>
export default class MyView extends Vue {
myObjs: MyObj[] = []
mounted () {
this.myObjs = await api.getGreatObjs()
// this.myObjs is like expected
}
}
wrapper.html()的内容:
控制台结果:
Expected: ""
Received: "<div class=\"container container--fluid\"><div class=\"container container--fluid\"><div></div></div>"
应为:“
收到:“”
“行”(
)或“div”(
)中没有任何内容,但应该有多个MyChild;所以,我不明白。
你能帮我吗?没有类型的问题与TypeScript无关。已删除标记。是否可以尝试更新包装器?等待包装器。forceUpdate();什么是“myObjs”?如何将它们传递到测试中的组件?@Berkay Kaan我尝试等待wrapper.vm.$forceUpdate(),但什么都没有(wrapper.forceUpdate()不存在)@Rara我在我的Vue类中有:myObjs:MyObj[]=[]。我通过Axios从API获得它们,但是我用:jest.spyOn(API,'getGreatObjs')来模拟它。mockImplementation(()=>new Promise((resolve,reject)=>{resolve([new MyObj({name:'toto',value:45}),…])没有类型的问题不是关于TypeScript的。已删除标记。是否可以尝试更新包装器?等待包装器。forceUpdate();什么是“myObjs”?如何将它们传递到测试中的组件?@Berkay Kaan我尝试等待wrapper.vm.$forceUpdate(),但什么都没有(wrapper.forceUpdate()不存在)@Rara我在我的Vue类中有:myObjs:MyObj[]=[]。我通过Axios从API获取它们,但是我用:jest.spyOn(API,'getGreatObjs').mockImplementation(()=>new Promise((resolve,reject)=>{resolve([new MyObj({name:'toto',value:45}),…])来模拟它)
<v-container fluid=\"\"><v-container fluid=\"\"><v-row></v-row></v-container></v-container>
describe('P1RealTime.vue', () => {
let wrapper: any
let localVue: any
beforeEach( () => {
localVue = createLocalVue()
localVue.use(Vuetify)
})
it('should render', () => {
wrapper = mount(MyView, {
localVue: localVue,
stubs: ['router-link']
})
expect(wrapper.html()).toEqual('')
})
})
Expected: ""
Received: "<div class=\"container container--fluid\"><div class=\"container container--fluid\"><div></div></div>"