2021-03-08 18:12:59 +05:30
|
|
|
export const getKey = (name) => `$_gl_jest_${name}`;
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
export const getBinding = (el, name) => el[getKey(name)];
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const writeBindingToElement = (el, name, { value, arg, modifiers }) => {
|
2020-07-28 23:09:34 +05:30
|
|
|
el[getKey(name)] = {
|
|
|
|
value,
|
|
|
|
arg,
|
|
|
|
modifiers,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
export const createMockDirective = (name) => {
|
|
|
|
if (!name) {
|
|
|
|
throw new Error(
|
|
|
|
'Vue 3 no longer passes the name of the directive to its hooks, an explicit name is required',
|
|
|
|
);
|
|
|
|
}
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
return {
|
|
|
|
bind(el, binding) {
|
|
|
|
writeBindingToElement(el, name, binding);
|
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
update(el, binding) {
|
|
|
|
writeBindingToElement(el, name, binding);
|
|
|
|
},
|
|
|
|
|
|
|
|
unbind(el) {
|
|
|
|
delete el[getKey(name)];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|