我正在测试动态路由到组件的组件。 但是问题是路由组件具有嵌套组件,我无法在路由组件中存根。及其抛出错误
我试图在shallowMount上添加所有嵌套组件的存根。将其添加到Vue.config.ignoredElements中,但使用$ router.push()却无济于事。
规格文件:
let wrapper = shallowMount(ExperimentDesignComponent, {
sync: false,
localVue,
router,
attachToDocument: true,
stubs: ['Wgrid','experimentDetails', 'customInjectionsGridFragment']
})
单元测试:
it('check setExperimentData experimentData', function () {
wrapper.vm.$router.push({
name: 'ExperimentDesign',
params: {'type': 'AutomatedIterativePrecursorExclusion'}
})
wrapper.vm.setExperimentData()
expect(wrapper.vm.storageFolder).toBe('')
})
路由组件:
<ExperimentDesignComponent>
<customInjectionsGridFragment>
<Wgrid></Wgrid>
</customInjectionsGridFragment>
</ExperimentDesignComponent>
created()挂钩在路由到ExperimentDsignComponent时被Wgrid调用。我已经将其存根,这不应该发生。