summaryrefslogtreecommitdiff
path: root/spec/frontend/behaviors/markdown/render_metrics_spec.js
blob: 6db0eabc16bfe4571342e090beaf781d85d09e7d (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
34
35
36
37
import Vue from 'vue';
import renderMetrics from '~/behaviors/markdown/render_metrics';
import { TEST_HOST } from 'helpers/test_constants';

const originalExtend = Vue.extend;

describe('Render metrics for Gitlab Flavoured Markdown', () => {
  const container = {
    Metrics() {},
  };

  let spyExtend;

  beforeEach(() => {
    Vue.extend = () => container.Metrics;
    spyExtend = jest.spyOn(Vue, 'extend');
  });

  afterEach(() => {
    Vue.extend = originalExtend;
  });

  it('does nothing when no elements are found', () => {
    renderMetrics([]);

    expect(spyExtend).not.toHaveBeenCalled();
  });

  it('renders a vue component when elements are found', () => {
    const element = document.createElement('div');
    element.setAttribute('data-dashboard-url', TEST_HOST);

    renderMetrics([element]);

    expect(spyExtend).toHaveBeenCalled();
  });
});