Skip to content

Commit 28383b8

Browse files
committed
fixes @typescript-eslint/no-unnecessary-type-assertion in tests
1 parent 32471ea commit 28383b8

File tree

7 files changed

+43
-48
lines changed

7 files changed

+43
-48
lines changed

packages/core/test/integrations/logEnricherIntegration.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('LogEnricher Integration', () => {
161161
// Extract the log handler
162162
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
163163
expect(beforeCaptureLogCall).toBeDefined();
164-
logHandler = beforeCaptureLogCall![1];
164+
logHandler = beforeCaptureLogCall[1];
165165

166166
mockLog = {
167167
message: 'Test log message',
@@ -245,7 +245,7 @@ describe('LogEnricher Integration', () => {
245245

246246
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
247247
expect(beforeCaptureLogCall).toBeDefined();
248-
const newLogHandler = beforeCaptureLogCall![1];
248+
const newLogHandler = beforeCaptureLogCall[1];
249249

250250
newLogHandler(mockLog);
251251

@@ -291,7 +291,7 @@ describe('LogEnricher Integration', () => {
291291

292292
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
293293
expect(beforeCaptureLogCall).toBeDefined();
294-
const emptyLogHandler = beforeCaptureLogCall![1];
294+
const emptyLogHandler = beforeCaptureLogCall[1];
295295

296296
emptyLogHandler(mockLog);
297297

@@ -323,7 +323,7 @@ describe('LogEnricher Integration', () => {
323323

324324
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
325325
expect(beforeCaptureLogCall).toBeDefined();
326-
const partialLogHandler = beforeCaptureLogCall![1];
326+
const partialLogHandler = beforeCaptureLogCall[1];
327327

328328
partialLogHandler(mockLog);
329329

@@ -357,7 +357,7 @@ describe('LogEnricher Integration', () => {
357357

358358
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
359359
expect(beforeCaptureLogCall).toBeDefined();
360-
const partialLogHandler = beforeCaptureLogCall![1];
360+
const partialLogHandler = beforeCaptureLogCall[1];
361361

362362
partialLogHandler(mockLog);
363363

@@ -447,7 +447,7 @@ describe('LogEnricher Integration', () => {
447447

448448
const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog');
449449
expect(beforeCaptureLogCall).toBeDefined();
450-
logHandler = beforeCaptureLogCall![1];
450+
logHandler = beforeCaptureLogCall[1];
451451

452452
mockLog = {
453453
message: 'Test log message',

packages/core/test/tracing/addTracingExtensions.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Tracing extensions', () => {
1515
test('transaction has default op', async () => {
1616
const transaction = startSpanManual({ name: 'parent' }, span => span);
1717

18-
expect(spanToJSON(transaction!)).toEqual(
18+
expect(spanToJSON(transaction)).toEqual(
1919
expect.objectContaining({
2020
op: 'default',
2121
}),
@@ -25,7 +25,7 @@ describe('Tracing extensions', () => {
2525
test('transaction does not overwrite custom op', async () => {
2626
const transaction = startSpanManual({ name: 'parent', op: 'custom' }, span => span);
2727

28-
expect(spanToJSON(transaction!)).toEqual(
28+
expect(spanToJSON(transaction)).toEqual(
2929
expect.objectContaining({
3030
op: 'custom',
3131
}),
@@ -36,7 +36,7 @@ describe('Tracing extensions', () => {
3636
startSpanManual({ name: 'parent', scope: getCurrentScope() }, () => {});
3737
const span = startSpanManual({ name: 'child', scope: getCurrentScope() }, span => span);
3838

39-
expect(spanToJSON(span!)).toEqual(
39+
expect(spanToJSON(span)).toEqual(
4040
expect.objectContaining({
4141
op: 'default',
4242
}),
@@ -47,7 +47,7 @@ describe('Tracing extensions', () => {
4747
startSpanManual({ name: 'parent', op: 'custom', scope: getCurrentScope() }, () => {});
4848
const span = startSpanManual({ name: 'child', op: 'custom', scope: getCurrentScope() }, span => span);
4949

50-
expect(spanToJSON(span!)).toEqual(
50+
expect(spanToJSON(span)).toEqual(
5151
expect.objectContaining({
5252
op: 'custom',
5353
}),
@@ -60,22 +60,22 @@ describe('Tracing extensions', () => {
6060
childSpan = startSpanManual({ name: 'child', scope: getCurrentScope() }, __span => __span);
6161
return _span;
6262
});
63-
childSpan!.end();
64-
transaction!.end();
63+
childSpan.end();
64+
transaction.end();
6565

6666
await client.flush();
6767
expect(client.event).toEqual(
6868
expect.objectContaining({
6969
contexts: expect.objectContaining({
7070
trace: expect.objectContaining({
71-
trace_id: transaction!.spanContext().traceId,
71+
trace_id: transaction.spanContext().traceId,
7272
}),
7373
}),
7474
}),
7575
);
76-
expect(spanToJSON(childSpan!)).toEqual(
76+
expect(spanToJSON(childSpan)).toEqual(
7777
expect.objectContaining({
78-
parent_span_id: spanToJSON(transaction!).span_id,
78+
parent_span_id: spanToJSON(transaction).span_id,
7979
}),
8080
);
8181
});

packages/core/test/tracing/integrations/appStart.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
21
import type { ErrorEvent, Event, Integration, SpanJSON, TransactionEvent } from '@sentry/core';
32
import {
43
getCurrentScope,
@@ -1198,7 +1197,7 @@ function expectEventWithStandaloneColdAppStart(
11981197
timestamp: expect.any(Number),
11991198
trace_id: expect.any(String),
12001199
span_id: expect.any(String),
1201-
parent_span_id: actualEvent!.contexts!.trace!.span_id,
1200+
parent_span_id: actualEvent.contexts.trace.span_id,
12021201
origin: SPAN_ORIGIN_AUTO_APP_START,
12031202
status: 'ok',
12041203
data: {
@@ -1249,7 +1248,7 @@ function expectEventWithStandaloneWarmAppStart(
12491248
timestamp: expect.any(Number),
12501249
trace_id: expect.any(String),
12511250
span_id: expect.any(String),
1252-
parent_span_id: actualEvent!.contexts!.trace!.span_id,
1251+
parent_span_id: actualEvent.contexts.trace.span_id,
12531252
origin: SPAN_ORIGIN_AUTO_APP_START,
12541253
status: 'ok',
12551254
data: {

packages/core/test/tracing/integrations/stallTracking/stalltracking.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
21
import type { Span } from '@sentry/core';
32
import {
43
getCurrentScope,
@@ -154,7 +153,7 @@ describe('StallTracking', () => {
154153
jest.runOnlyPendingTimers();
155154
});
156155
jest.runOnlyPendingTimers();
157-
rootSpan!.end(childSpanEnd);
156+
rootSpan.end(childSpanEnd);
158157

159158
await client.flush();
160159

@@ -170,7 +169,7 @@ describe('StallTracking', () => {
170169
jest.runOnlyPendingTimers();
171170
});
172171
jest.runOnlyPendingTimers();
173-
rootSpan!.end(childSpanEnd! + 20);
172+
rootSpan.end(childSpanEnd! + 20);
174173

175174
await client.flush();
176175

packages/core/test/tracing/integrations/userInteraction.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
21
import type { Span } from '@sentry/core';
32
import {
43
getActiveSpan,
@@ -213,7 +212,7 @@ describe('User Interaction Tracing', () => {
213212
op: 'different.op',
214213
}),
215214
);
216-
expect(firstTransactionEvent!.timestamp).toBeGreaterThanOrEqual(spanToJSON(secondTransaction!).start_timestamp!);
215+
expect(firstTransactionEvent.timestamp).toBeGreaterThanOrEqual(spanToJSON(secondTransaction).start_timestamp!);
217216
});
218217

219218
test('different UI event and same element finish first transaction with last span', () => {
@@ -253,9 +252,9 @@ describe('User Interaction Tracing', () => {
253252

254253
const firstTransactionContext = spanToJSON(firstTransaction!);
255254
const secondTransactionContext = spanToJSON(secondTransaction!);
256-
expect(firstTransactionContext!.timestamp).toEqual(expect.any(Number));
257-
expect(secondTransactionContext!.timestamp).toEqual(expect.any(Number));
258-
expect(firstTransactionContext!.span_id).not.toEqual(secondTransactionContext!.span_id);
255+
expect(firstTransactionContext.timestamp).toEqual(expect.any(Number));
256+
expect(secondTransactionContext.timestamp).toEqual(expect.any(Number));
257+
expect(firstTransactionContext.span_id).not.toEqual(secondTransactionContext.span_id);
259258
});
260259

261260
test('do not start UI event transaction if active transaction on scope', () => {
@@ -298,7 +297,7 @@ describe('User Interaction Tracing', () => {
298297
timestamp: expect.any(Number),
299298
}),
300299
);
301-
expect(interactionTransactionContext!.timestamp).toBeLessThanOrEqual(routingTransactionContext!.start_timestamp!);
300+
expect(interactionTransactionContext.timestamp).toBeLessThanOrEqual(routingTransactionContext.start_timestamp!);
302301
});
303302

304303
test('does not start UI span when app is in background', () => {

packages/core/test/tracing/reactnavigation.ttid.test.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
21
import type { Scope, Span, SpanJSON, TransactionEvent, Transport } from '@sentry/core';
32
import { getActiveSpan, spanToJSON, timestampInSeconds } from '@sentry/core';
43
import * as TestRenderer from '@testing-library/react-native'
@@ -286,10 +285,10 @@ describe('React Navigation - TTID', () => {
286285
TestRenderer.render(<TimeToFullDisplay record />);
287286
mockRecordedTimeToDisplay({
288287
ttidNavigation: {
289-
[spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(),
288+
[spanToJSON(getActiveSpan()).span_id!]: nowInSeconds(),
290289
},
291290
ttfd: {
292-
[spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(),
291+
[spanToJSON(getActiveSpan()).span_id!]: nowInSeconds(),
293292
},
294293
});
295294

@@ -363,10 +362,10 @@ describe('React Navigation - TTID', () => {
363362
TestRenderer.render(<TimeToFullDisplay record />);
364363
mockRecordedTimeToDisplay({
365364
ttidNavigation: {
366-
[spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(),
365+
[spanToJSON(getActiveSpan()).span_id]: timestampInSeconds(),
367366
},
368367
ttfd: {
369-
[spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds() - 1,
368+
[spanToJSON(getActiveSpan()).span_id]: timestampInSeconds() - 1,
370369
},
371370
});
372371

@@ -390,10 +389,10 @@ describe('React Navigation - TTID', () => {
390389
TestRenderer.render(<TimeToFullDisplay record />);
391390
mockRecordedTimeToDisplay({
392391
ttidNavigation: {
393-
[spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(),
392+
[spanToJSON(getActiveSpan()).span_id!]: timestampInSeconds(),
394393
},
395394
ttfd: {
396-
[spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(),
395+
[spanToJSON(getActiveSpan()).span_id!]: timestampInSeconds(),
397396
},
398397
});
399398

@@ -490,7 +489,7 @@ describe('React Navigation - TTID', () => {
490489
timeToDisplayComponent.update(<TimeToInitialDisplay record />);
491490
mockRecordedTimeToDisplay({
492491
ttid: {
493-
[spanToJSON(getActiveSpan()!).span_id!]: manualInitialDisplayEndTimestampMs / 1_000,
492+
[spanToJSON(getActiveSpan()).span_id]: manualInitialDisplayEndTimestampMs / 1_000,
494493
},
495494
});
496495

@@ -671,7 +670,7 @@ describe('React Navigation - TTID', () => {
671670
function mockAutomaticTimeToDisplay(): void {
672671
mockRecordedTimeToDisplay({
673672
ttidNavigation: {
674-
[spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(),
673+
[spanToJSON(getActiveSpan()).span_id]: nowInSeconds(),
675674
},
676675
});
677676
}

packages/core/test/tracing/timetodisplay.test.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable @typescript-eslint/no-unnecessary-type-assertion
21
import type { Event, Measurements, Span, SpanJSON } from '@sentry/core';
32
import { debug , getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, spanToJSON, startSpanManual } from '@sentry/core';
43

@@ -72,7 +71,7 @@ describe('TimeToDisplay', () => {
7271
render(<TimeToInitialDisplay record={true} />);
7372
mockRecordedTimeToDisplay({
7473
ttid: {
75-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
74+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
7675
},
7776
});
7877

@@ -103,10 +102,10 @@ describe('TimeToDisplay', () => {
103102

104103
mockRecordedTimeToDisplay({
105104
ttid: {
106-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
105+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
107106
},
108107
ttfd: {
109-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
108+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
110109
},
111110
});
112111

@@ -135,7 +134,7 @@ describe('TimeToDisplay', () => {
135134

136135
mockRecordedTimeToDisplay({
137136
ttfd: {
138-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
137+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
139138
},
140139
});
141140

@@ -165,7 +164,7 @@ describe('TimeToDisplay', () => {
165164

166165
mockRecordedTimeToDisplay({
167166
ttid: {
168-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
167+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
169168
},
170169
});
171170

@@ -196,10 +195,10 @@ describe('TimeToDisplay', () => {
196195

197196
mockRecordedTimeToDisplay({
198197
ttid: {
199-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
198+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
200199
},
201200
ttfd: {
202-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
201+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
203202
},
204203
});
205204

@@ -231,10 +230,10 @@ describe('TimeToDisplay', () => {
231230

232231
mockRecordedTimeToDisplay({
233232
ttid: {
234-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds(),
233+
[spanToJSON(activeSpan).span_id]: nowInSeconds(),
235234
},
236235
ttfd: {
237-
[spanToJSON(activeSpan!).span_id!]: nowInSeconds() + 40,
236+
[spanToJSON(activeSpan).span_id]: nowInSeconds() + 40,
238237
},
239238
});
240239

@@ -271,10 +270,10 @@ describe('TimeToDisplay', () => {
271270

272271
mockRecordedTimeToDisplay({
273272
ttfd: {
274-
[spanToJSON(activeSpan!).span_id!]: fullDisplayEndTimestampMs / 1_000,
273+
[spanToJSON(activeSpan).span_id]: fullDisplayEndTimestampMs / 1_000,
275274
},
276275
ttid: {
277-
[spanToJSON(activeSpan!).span_id!]: initialDisplayEndTimestampMs / 1_000,
276+
[spanToJSON(activeSpan).span_id]: initialDisplayEndTimestampMs / 1_000,
278277
},
279278
});
280279

0 commit comments

Comments
 (0)