Search code examples
javascriptvue.jstestingcypresscypress-component-test-runner

Register global custom directive for cypress component testing in vue


Is there way register global custom directive for cypress component testing in vue. Just register with

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

in main.js file can't solve problem. Because in the component testing component failed resolve that directive.

Local register like that:

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

isn't good option. Because i use this directive in every component and need local register in every component.

How i can register global directive for cypress component testing ?

Thanxx


Solution

  • Create your own mount,

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

    Put it in /cypress/support/index.js or another file of your choosing.

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