Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vue_mock_directive.js « __helpers__ « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7a2aa7f10d68f12e4ce686a42b2e194cc89f1e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const getKey = (name) => `$_gl_jest_${name}`;

export const getBinding = (el, name) => el[getKey(name)];

const writeBindingToElement = (el, name, { value, arg, modifiers }) => {
  el[getKey(name)] = {
    value,
    arg,
    modifiers,
  };
};

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

  return {
    bind(el, binding) {
      writeBindingToElement(el, name, binding);
    },

    update(el, binding) {
      writeBindingToElement(el, name, binding);
    },

    unbind(el) {
      delete el[getKey(name)];
    },
  };
};