Vue.js Vue,如何测试子组件(通过v-show显示)是否可见
我试图弄清楚如何测试(使用vue test utils&jest)子组件(通过Vue.js Vue,如何测试子组件(通过v-show显示)是否可见,vue.js,jestjs,vue-component,vue-test-utils,Vue.js,Jestjs,Vue Component,Vue Test Utils,我试图弄清楚如何测试(使用vue test utils&jest)子组件(通过v-show显示)当前是否可见(与子组件的内容无关) 我的vue html代码如下所示: <ChildComponent v-show="isShowing"/> 我知道如何测试它是否正在使用v-if: expect(wrapper.findComponent(ChildComponent).exists()).toBe(true) //it is conditionally rend
v-show
显示)当前是否可见(与子组件的内容无关)
我的vue html代码如下所示:
<ChildComponent v-show="isShowing"/>
我知道如何测试它是否正在使用v-if
:
expect(wrapper.findComponent(ChildComponent).exists()).toBe(true) //it is conditionally rendered
expect(wrapper.findComponent(ChildComponent).exists()).toBe(false) //it is not conditionally rendered
谁能给我指一下正确的方向吗?提前谢谢 有一种方法可以测试,使用方法
isVisible()
方法检查显示:无
与否,还可以测试可见性:隐藏
与不透明度:0
下面是一个代码示例:
expect(wrapper.findComponent(ChildComponent).isVisible()).toBe(true)
如果该组件是主包装器,则如下所示:
expect(wrapper.isVisible()).toBe(true)
有一种方法可以通过使用方法进行测试
isVisible()
方法检查显示:无
与否,还可以测试可见性:隐藏
与不透明度:0
下面是一个代码示例:
expect(wrapper.findComponent(ChildComponent).isVisible()).toBe(true)
如果该组件是主包装器,则如下所示:
expect(wrapper.isVisible()).toBe(true)
你好,里亚兹,谢谢你的回答。当我尝试这段代码时,我得到了:
TypeError:wrapper.findComponent(…).isVisible不是一个函数
@Clarity我相信它在获取childComponent元素时有问题,请使用wrapper.find('.class name comp').isVisible()
@Clarity,如果该组件是主包装,那么像这样使用:expect(wrapper.isVisible()).toBe(true)
Hi Riyaz,谢谢你的回答。当我尝试这段代码时,我得到:TypeError:wrapper.findComponent(…).isVisible不是一个函数
@Clarity我相信它在获取childComponent元素时有问题,请使用wrapper.find('.class name comp').isVisible()
@clearity如果该组件是主包装器,则如下使用:expect(wrapper.isVisible()).toBe(true)