1

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

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

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

像这样的本地寄存器:

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

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

我如何注册柏树组件测试的全局指令?

谢谢

4

1 回答 1

0

创建自己的坐骑,

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)
于 2022-02-26T06:00:16.807 回答