forked from SnakeByteDevelopment/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngx-analytics-hubspot.spec.ts
62 lines (53 loc) · 1.93 KB
/
ngx-analytics-hubspot.spec.ts
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
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgxAnalytics } from 'ngx-analytics';
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks';
import { NgxAnalyticsHubspot } from './ngx-analytics-hubspot';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;
describe('NgxAnalyticsHubspot', () => {
let _hsq: Array<any>;
let fixture: ComponentFixture<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestModule],
providers: [NgxAnalyticsHubspot],
});
window._hsq = _hsq = [];
});
it('should track pages',
fakeAsync(inject([NgxAnalytics, NgxAnalyticsHubspot],
(ngxAnalytics: NgxAnalytics, ngxAnalyticsHubspot: NgxAnalyticsHubspot) => {
fixture = createRoot(RootCmp);
ngxAnalytics.pageTrack.next({ path: '/abc' });
advance(fixture);
expect(_hsq).toContain([ 'setPath', '/abc' ], [ 'trackPageView' ]);
}),
),
);
it('should track events',
fakeAsync(inject([NgxAnalytics, NgxAnalyticsHubspot],
(ngxAnalytics: NgxAnalytics, ngxAnalyticsHubspot: NgxAnalyticsHubspot) => {
fixture = createRoot(RootCmp);
ngxAnalytics.eventTrack.next({
action: 'unused',
properties: { id: 'Clicked Buy Now button', value: 20.5 },
});
advance(fixture);
expect(_hsq).toContain([
'trackEvent',
{ id: 'Clicked Buy Now button', value: 20.5 },
]);
}),
),
);
it('should set user properties',
fakeAsync(inject([NgxAnalytics, NgxAnalyticsHubspot],
(ngxAnalytics: NgxAnalytics, ngxAnalyticsHubspot: NgxAnalyticsHubspot) => {
fixture = createRoot(RootCmp);
ngxAnalytics.setUserProperties.next({ email: '[email protected]', id: '1234' });
advance(fixture);
expect(_hsq).toContain(['identify', { email: '[email protected]', id: '1234' }]);
}),
),
);
});