-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathindex.test.js
100 lines (85 loc) · 2.3 KB
/
index.test.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var Analytics = require('@segment/analytics.js-core').constructor;
var integration = require('@segment/analytics.js-integration');
var sandbox = require('@segment/clear-env');
var tester = require('@segment/analytics.js-integration-tester');
var Hellobar = require('../lib/');
describe('Hellobar', function() {
var analytics;
var hellobar;
var options = {
apiKey: 'a18c23dec1b87e9401465165eca61459d405684d'
};
beforeEach(function() {
analytics = new Analytics();
hellobar = new Hellobar(options);
analytics.use(Hellobar);
analytics.use(tester);
analytics.add(hellobar);
});
afterEach(function() {
analytics.restore();
analytics.reset();
hellobar.reset();
sandbox();
});
afterEach(function() {
reset();
});
it('should have the right settings', function() {
analytics.compare(
Hellobar,
integration('Hello Bar')
.assumesPageview()
.option('apiKey', '')
);
});
describe('before loading', function() {
beforeEach(function() {
analytics.stub(hellobar, 'load');
});
describe('#initialize', function() {
it('should call #load', function() {
analytics.initialize();
analytics.page();
analytics.called(hellobar.load);
});
});
});
describe('loading', function() {
it('should load', function(done) {
analytics.load(hellobar, done);
});
});
describe('after loading', function() {
beforeEach(function(done) {
analytics.initialize();
analytics.page();
analytics.once('ready', done);
});
describe('#track', function() {
beforeEach(function() {
analytics.stub(window.hellobar.trigger, 'event');
});
it('should send trigger an event', function() {
analytics.track('event');
analytics.called(window.hellobar.trigger.event, 'event', {});
});
it('should send a trigger event and properties', function() {
analytics.track('event', {
property: true
});
analytics.called(window.hellobar.trigger.event, 'event', {
property: true
});
});
});
});
});
/**
* Remove the Hellobar DOM element.
*/
function reset() {
var el = document.getElementById('hellobar_container');
if (el) el.parentNode.removeChild(el);
}