Vue测试实用程序:未定义插槽的属性

时间:2020-04-23 10:54:46

标签: vue.js jestjs vue-test-utils

当前,我正在使用Vue.js开发前端应用程序,并且正在使用Vue Test Utils + Jest测试我的组件。

我有一个组件,该组件包装了实质上是插槽的组件列表。

在beforeEach函数中,我模拟了此插槽。

    stepContent1 = {
    render(h) {
      return h(StepContent, { props: { title: "Step1", subTitle: 'Subtitle for Step 1', stepKey: 'stepOne' } });
    },
  };

  stepContent2 = {
    render(h) {
      return h(StepContent, { props: { title: "Step2", subTitle: 'Subtitle for Step 2', stepKey: 'stepTwo' } });
    },
  };

  stepContent3 = {
    render(h) {
      return h(StepContent, { props: { title: "Step3", subTitle: 'Subtitle for Step 3', stepKey: 'stepThree' } });
    },
  };

然后我将插槽传递给shallowMount

const wrapper = shallowMount(FormWizard, {
slots: {
  default: [stepContent1, stepContent2, stepContent3],
},
mocks,

});

如果我用这种方法检查道具。

wrapper.findAll(StepContent).wrappers[0].vm.stepKey

我可以获得老虎机道具。但是,如果要进行黑盒测试,例如在FormWizard中触发依赖于StepContent道具的单击,则StepContent插槽的道具是未定义的。

知道为什么会发生这种情况吗?

谢谢。

0 个答案:

没有答案