首页  >  问答  >  正文

在vue中注册用于cypress组件测试的全局自定义指令

有没有办法在 vue.js 中注册用于 cypress 组件测试的全局自定义指令。只需注册

app.directive('some',(el,binding)=>{{...})

main.js 文件中无法解决问题。因为在组件测试组件中未能解析该指令。

像这样的本地寄存器:

mount(SomeComp,{
directive:{
  'some': {...}
})

不是一个好的选择。因为我在每个组件中都使用这个指令,并且需要在每个组件中本地注册。

我如何注册用于赛普拉斯组件测试的全局指令?

谢谢

P粉529581199P粉529581199206 天前432

全部回复(1)我来回复

  • P粉884667022

    P粉8846670222024-03-27 12:13:02

    创建你自己的坐骑,

    import { mount } from '@cypress/vue'
    
    export const mountWithDirective = (myComponent) => {
    
      return mount(myComponent, {
        directive:{
          'some': {...}
      })
    }
    

    将其放入 /cypress/support/index.js 或您选择的其他文件中。

    // test
    import { mountWithDirective } from 'cypress/support'
    import Component from './Component.vue'
    
    it...
      mountWithDirective(Component)
    

    回复
    0
  • 取消回复