是否有一种测试功能组件的方法,该功能组件可以从this.$copedSlots.default()
方法中返回render
?
我所追求的例子:
组件
<script>
export default {
name: 'TestComponent',
props: {
fields: {
type: Object,
default: () => {
return {};
},
},
},
data() {
return {
inputs: this.fields,
};
},
render() {
return this.$scopedSlots.default({
fields: this.inputs,
});
},
watch: {
fields(newValue) {
this.inputs = newValue;
},
},
};
</script>
测试
describe('TestComponent.vue', () => {
it('Returns correct fields when props.fields is passed', () => {
const fields = {
name: 'Jon Joe',
email: 'jon@doe.com',
};
const wrapper = shallowMount(TestComponent, {
propsData: { fields },
});
//... how to check props returned with the render() function
});
});
此刻我在运行此测试时遇到错误
TypeError:this。$ scopedSlots.default不是函数