This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
2022-04-11 20:08:28 +00:00
|
|
|
import type {Directive} from 'vue'
|
2021-11-22 21:36:17 +00:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
Cypress: object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:59:12 +00:00
|
|
|
const cypressDirective = <Directive<HTMLElement,string>>{
|
|
|
|
mounted(el, {arg, value}) {
|
|
|
|
const testingId = arg || value
|
|
|
|
if ((window.Cypress || import.meta.env.DEV) && testingId) {
|
|
|
|
el.setAttribute('data-cy', testingId)
|
2021-11-22 21:36:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount(el) {
|
|
|
|
el.removeAttribute('data-cy')
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default cypressDirective
|