-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathindex.test.js
116 lines (101 loc) · 2.88 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'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 ReplayBird = require('../lib/');
describe('ReplayBird', function() {
var analytics;
var replaybird;
var options = {
siteKey: '7vrdFkeywUwS94YQXUTdBf0pPQHXNlcWihmo1gsKLBO',
debug: false
};
beforeEach(function() {
analytics = new Analytics();
replaybird = new ReplayBird(options);
analytics.use(ReplayBird);
analytics.use(tester);
analytics.add(replaybird);
});
afterEach(function() {
analytics.restore();
analytics.reset();
replaybird.reset();
sandbox();
});
it('should have the right settings', function() {
analytics.compare(
ReplayBird,
integration('ReplayBird')
.option('siteKey', '')
.option('debug', false)
);
});
describe('before loading', function() {
beforeEach(function() {
analytics.stub(replaybird, 'load');
});
describe('#initialize', function() {
it('should call #load', function() {
analytics.initialize();
analytics.called(replaybird.load);
});
});
});
describe('after loading', function() {
beforeEach(function(done) {
analytics.once('ready', done);
analytics.initialize();
analytics.page();
});
describe('#identify', function() {
beforeEach(function() {
analytics.stub(window.ReplayBird, 'identify');
});
it('should send an id', function() {
analytics.identify('id');
analytics.called(window.ReplayBird.identify, 'id', {});
});
it('should camel case custom props', function() {
analytics.identify('id', {
name: 'User123',
email: '[email protected]',
'First name': 'Eric',
lastName: 'Brown'
});
analytics.called(
window.ReplayBird.identify,
'id',
{
name: 'User123',
email: '[email protected]',
firstName: 'Eric',
lastName: 'Brown'
}
);
});
it('should map name and email', function() {
analytics.identify('id', { name: 'Test', email: '[email protected]' });
analytics.called(
window.ReplayBird.identify,
'id',
{ name: 'Test', email: '[email protected]' }
);
});
});
describe('#track', function() {
beforeEach(function() {
analytics.stub(window.ReplayBird, 'event');
});
it('should send track event name and properties', function() {
analytics.track('my_event', { some_field: 'field_value' });
analytics.called(
window.ReplayBird.event,
'my_event',
{ some_field: 'field_value' }
);
});
});
});
});