|
| 1 | +import { NavigationStart, Router, RouterEvent } from '@angular/router'; |
| 2 | +import { Subject } from 'rxjs'; |
| 3 | + |
| 4 | +import { instrumentAngularRouting, TraceService } from '../src/index'; |
| 5 | + |
| 6 | +describe('Angular Tracing', () => { |
| 7 | + const startTransaction = jest.fn(); |
| 8 | + describe('instrumentAngularRouting', () => { |
| 9 | + it('should attach the transaction source on the pageload transaction', () => { |
| 10 | + instrumentAngularRouting(startTransaction); |
| 11 | + expect(startTransaction).toHaveBeenCalledWith({ |
| 12 | + name: '/', |
| 13 | + op: 'pageload', |
| 14 | + metadata: { source: 'url' }, |
| 15 | + }); |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + describe('TraceService', () => { |
| 20 | + let traceService: TraceService; |
| 21 | + const routerEvents$: Subject<RouterEvent> = new Subject(); |
| 22 | + |
| 23 | + beforeAll(() => instrumentAngularRouting(startTransaction)); |
| 24 | + beforeEach(() => { |
| 25 | + jest.resetAllMocks(); |
| 26 | + |
| 27 | + traceService = new TraceService({ |
| 28 | + events: routerEvents$, |
| 29 | + } as unknown as Router); |
| 30 | + }); |
| 31 | + |
| 32 | + afterEach(() => { |
| 33 | + traceService.ngOnDestroy(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('attaches the transaction source on a navigation change', () => { |
| 37 | + routerEvents$.next(new NavigationStart(0, 'user/123/credentials')); |
| 38 | + |
| 39 | + expect(startTransaction).toHaveBeenCalledTimes(1); |
| 40 | + expect(startTransaction).toHaveBeenCalledWith({ |
| 41 | + name: 'user/123/credentials', |
| 42 | + op: 'navigation', |
| 43 | + metadata: { source: 'url' }, |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
0 commit comments