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>
export default class MyView extends Vue {
myObjs: MyObj[] = []
mounted () {
this.myObjs = await api.getGreatObjs()
// this.myObjs is like expected
}
}
MyView.spe c .ts:
beforeEach( () => {
localVue = createLocalVue()
localVue.use(Vuetify)
jest.mock('axios')
jest.spyOn(api, 'getGreatObjs')
.mockImplementation( () => new Promise((resolve, reject) => {
resolve([new MyObj({name: 'toto', value: 45}), ...])
}))
})
it('should render', () => {
wrapper = mount(MyView, {
stubs: ['router-link']
})
expect(wrapper.findAll(MyChild).length).toBe(2)
})
Содержимое оболочки. html ():
<v-container fluid=\"\"><v-container fluid=\"\"><v-row></v-row></v-container></v-container>
Я также пробовал это (MyView.spe c .ts):
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>"
В "строке" нет ничего (<v-row></v-row>
) или "div" (<div></div>
), но должно быть несколько MyChild; так что я не понимаю Не могли бы вы помочь мне?