Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue,如何测试子组件(通过v-show显示)是否可见_Vue.js_Jestjs_Vue Component_Vue Test Utils - Fatal编程技术网

Vue.js Vue,如何测试子组件(通过v-show显示)是否可见

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

我试图弄清楚如何测试(使用vue test utils&jest)子组件(通过
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)