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
38
39
40
41
42
43
44
45
46
47
48
49
|
import Vue from 'vue';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Tracking from '~/tracking';
import TrackEvent from '~/vue_shared/directives/track_event';
jest.mock('~/tracking');
const Component = Vue.component('dummy-element', {
directives: {
TrackEvent,
},
data() {
return {
trackingOptions: null,
};
},
template: '<button id="trackable" v-track-event="trackingOptions"></button>',
});
const localVue = createLocalVue();
let wrapper;
let button;
describe('Error Tracking directive', () => {
beforeEach(() => {
wrapper = shallowMount(localVue.extend(Component), {
localVue,
});
button = wrapper.find('#trackable');
});
it('should not track the event if required arguments are not provided', () => {
button.trigger('click');
expect(Tracking.event).not.toHaveBeenCalled();
});
it('should track event on click if tracking info provided', () => {
const trackingOptions = {
category: 'Tracking',
action: 'click_trackable_btn',
label: 'Trackable Info',
};
wrapper.setData({ trackingOptions });
const { category, action, label, property, value } = trackingOptions;
button.trigger('click');
expect(Tracking.event).toHaveBeenCalledWith(category, action, { label, property, value });
});
});
|