Skip to content

Commit d223800

Browse files
committed
wip tests (no real progress :( )
1 parent 96ec73d commit d223800

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

packages/angular/test/tracing.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Hub } from '@sentry/types';
44

55
import { instrumentAngularRouting, TraceClassDecorator, TraceDirective, TraceMethodDecorator } from '../src';
66
import { getParameterizedRouteFromSnapshot } from '../src/tracing';
7-
import { AppComponent, TestEnv } from './utils/index';
7+
import { AppComponent, TestEnv, TestViewContainerRef } from './utils/index';
88

99
let transaction: any;
1010

@@ -265,15 +265,15 @@ describe('Angular Tracing', () => {
265265

266266
@Component({
267267
selector: 'app-component',
268-
template: `<app-child trace></app-child>`,
268+
template: '<app-child trace></app-child>',
269269
})
270270
class AppComponent {
271271
public constructor() {}
272272
}
273273

274274
@Component({
275275
selector: 'app-child',
276-
template: `<p>Hi</p>`,
276+
template: '<p>Hi</p>',
277277
})
278278
class ChildComponent {
279279
public constructor() {}
@@ -288,7 +288,7 @@ describe('Angular Tracing', () => {
288288

289289
transaction.startChild = jest.fn();
290290

291-
//directive.ngOnInit();
291+
// directive.ngOnInit();
292292

293293
expect(transaction.startChild).toHaveBeenCalledWith({
294294
op: 'ui.angular.init',
@@ -299,7 +299,7 @@ describe('Angular Tracing', () => {
299299
});
300300

301301
it('should create a child tracingSpan on init', async () => {
302-
//const directive = new TraceDirective({} as unknown as any);
302+
// const directive = new TraceDirective({} as unknown as any);
303303
const customStartTransaction = jest.fn(defaultStartTransaction);
304304

305305
const env = await TestEnv.setup({
@@ -310,7 +310,7 @@ describe('Angular Tracing', () => {
310310

311311
transaction.startChild = jest.fn();
312312

313-
//directive.ngOnInit();
313+
// directive.ngOnInit();
314314

315315
expect(transaction.startChild).toHaveBeenCalledWith({
316316
op: 'ui.angular.init',
@@ -347,7 +347,8 @@ describe('Angular Tracing', () => {
347347
});
348348

349349
it('should finish tracingSpan after view init', async () => {
350-
const directive = new TraceDirective({} as unknown as any);
350+
// @ts-ignore - we don't need to pass a param here
351+
const directive = new TraceDirective(new TestViewContainerRef());
351352
const finishMock = jest.fn();
352353
const customStartTransaction = jest.fn(defaultStartTransaction);
353354

packages/angular/test/utils/index.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, NgModule } from '@angular/core';
1+
import { Component, NgModule, ViewContainerRef } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { Router, Routes } from '@angular/router';
44
import { RouterTestingModule } from '@angular/router/testing';
@@ -65,7 +65,12 @@ export class TestEnv {
6565
deps: [Router],
6666
},
6767
]
68-
: [],
68+
: [
69+
{
70+
provide: ViewContainerRef,
71+
useValue: new TestViewContainerRef(),
72+
},
73+
],
6974
});
7075

7176
const router: Router = TestBed.inject(Router);
@@ -94,3 +99,56 @@ export class TestEnv {
9499
jest.clearAllMocks();
95100
}
96101
}
102+
103+
// create the test class
104+
export class TestViewContainerRef extends ViewContainerRef {
105+
get element(): import('@angular/core').ElementRef<any> {
106+
throw new Error('Method not implemented.');
107+
}
108+
get injector(): import('@angular/core').Injector {
109+
throw new Error('Method not implemented.');
110+
}
111+
get parentInjector(): import('@angular/core').Injector {
112+
throw new Error('Method not implemented.');
113+
}
114+
clear(): void {
115+
throw new Error('Method not implemented.');
116+
}
117+
get(_index: number): import('@angular/core').ViewRef {
118+
throw new Error('Method not implemented.');
119+
}
120+
get length(): number {
121+
throw new Error('Method not implemented.');
122+
}
123+
createEmbeddedView<C>(
124+
_templateRef: import('@angular/core').TemplateRef<C>,
125+
_context?: C,
126+
_index?: number,
127+
): import('@angular/core').EmbeddedViewRef<C> {
128+
throw new Error('Method not implemented.');
129+
}
130+
createComponent<C>(
131+
_componentFactory: import('@angular/core').ComponentFactory<C>,
132+
_index?: number,
133+
_injector?: import('@angular/core').Injector,
134+
_projectableNodes?: any[][],
135+
_ngModule?: import('@angular/core').NgModuleRef<any>,
136+
): import('@angular/core').ComponentRef<C> {
137+
throw new Error('Method not implemented.');
138+
}
139+
insert(_viewRef: import('@angular/core').ViewRef, _index?: number): import('@angular/core').ViewRef {
140+
throw new Error('Method not implemented.');
141+
}
142+
move(_viewRef: import('@angular/core').ViewRef, _currentIndex: number): import('@angular/core').ViewRef {
143+
throw new Error('Method not implemented.');
144+
}
145+
indexOf(_viewRef: import('@angular/core').ViewRef): number {
146+
throw new Error('Method not implemented.');
147+
}
148+
remove(_index?: number): void {
149+
throw new Error('Method not implemented.');
150+
}
151+
detach(_index?: number): import('@angular/core').ViewRef {
152+
throw new Error('Method not implemented.');
153+
}
154+
}

0 commit comments

Comments
 (0)