forked from angulartics/angulartics2
/
ngx-analytics-facebook.spec.ts
51 lines (43 loc) · 1.54 KB
/
ngx-analytics-facebook.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
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgxAnalytics } from 'ngx-analytics';
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks';
import { NgxAnalyticsFacebook } from './ngx-analytics-facebook';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;
describe('NgxAnalyticsFacebook', () => {
let fbq: any;
let fixture: ComponentFixture<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestModule],
providers: [NgxAnalyticsFacebook],
});
window.fbq = fbq = jasmine.createSpy('fbq');
});
it('should track events',
fakeAsync(inject([NgxAnalytics, NgxAnalyticsFacebook],
(ngxAnalytics: NgxAnalytics, ngxAnalyticsFacebook: NgxAnalyticsFacebook) => {
fixture = createRoot(RootCmp);
ngxAnalytics.eventTrack.next({
action: 'ViewContent',
properties: { category: 'cat' },
});
advance(fixture);
expect(fbq).toHaveBeenCalledWith('track', 'ViewContent', { category: 'cat' });
}),
),
);
it('should track custom events',
fakeAsync(inject([NgxAnalytics, NgxAnalyticsFacebook],
(ngxAnalytics: NgxAnalytics, ngxAnalyticsFacebook: NgxAnalyticsFacebook) => {
fixture = createRoot(RootCmp);
ngxAnalytics.eventTrack.next({
action: 'do',
properties: { category: 'cat' },
});
advance(fixture);
expect(fbq).toHaveBeenCalledWith('trackCustom', 'do', { category: 'cat' });
}),
),
);
});