debian-mirror-gitlab/spec/frontend/__helpers__/vue_mock_directive.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
685 B
JavaScript
Raw Normal View History

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)];
},
};
};