Skip to content

Commit 638d328

Browse files
committed
fix type errors in integrations tests
1 parent 1a8ec2c commit 638d328

File tree

5 files changed

+55
-52
lines changed

5 files changed

+55
-52
lines changed

packages/integrations/test/captureconsole.test.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Event, Integration } from '@sentry/types';
1+
/* eslint-disable @typescript-eslint/unbound-method */
2+
import { Event, Hub, Integration } from '@sentry/types';
23

34
import { CaptureConsole } from '../src/captureconsole';
45

@@ -25,10 +26,11 @@ const mockConsole = {
2526
info: jest.fn(),
2627
};
2728

28-
const getMockHubWithIntegration = (integration: Integration) => ({
29-
...mockHub,
30-
getIntegration: jest.fn(() => integration),
31-
});
29+
const getMockHubWithIntegration = (integration: Integration) =>
30+
({
31+
...mockHub,
32+
getIntegration: jest.fn(() => integration),
33+
} as unknown as Hub);
3234

3335
// We're using this to un-monkey patch the console after each test.
3436
const originalConsole = Object.assign({}, global.console);
@@ -59,7 +61,7 @@ describe('CaptureConsole setup', () => {
5961
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'warn'] });
6062
captureConsoleIntegration.setupOnce(
6163
() => undefined,
62-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
64+
() => getMockHubWithIntegration(captureConsoleIntegration),
6365
);
6466

6567
expect(global.console.error).toBe(originalConsole.error); // not monkey patched
@@ -71,7 +73,7 @@ describe('CaptureConsole setup', () => {
7173
const captureConsoleIntegration = new CaptureConsole();
7274
captureConsoleIntegration.setupOnce(
7375
() => undefined,
74-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
76+
() => getMockHubWithIntegration(captureConsoleIntegration),
7577
);
7678

7779
// expect a set of defined console levels to have been monkey patched
@@ -91,7 +93,7 @@ describe('CaptureConsole setup', () => {
9193
const captureConsoleIntegration = new CaptureConsole({ levels: [] });
9294
captureConsoleIntegration.setupOnce(
9395
() => undefined,
94-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
96+
() => getMockHubWithIntegration(captureConsoleIntegration),
9597
);
9698

9799
// expect the default set of console levels not to have been monkey patched
@@ -120,7 +122,7 @@ describe('CaptureConsole setup', () => {
120122
const captureConsoleIntegration = new CaptureConsole();
121123
captureConsoleIntegration.setupOnce(
122124
() => undefined,
123-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
125+
() => getMockHubWithIntegration(captureConsoleIntegration),
124126
);
125127
}).not.toThrow();
126128

@@ -132,7 +134,7 @@ describe('CaptureConsole setup', () => {
132134
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
133135
captureConsoleIntegration.setupOnce(
134136
() => undefined,
135-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
137+
() => getMockHubWithIntegration(captureConsoleIntegration),
136138
);
137139

138140
// call a wrapped function
@@ -146,7 +148,7 @@ describe('CaptureConsole setup', () => {
146148
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
147149
captureConsoleIntegration.setupOnce(
148150
() => undefined,
149-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
151+
() => getMockHubWithIntegration(captureConsoleIntegration),
150152
);
151153

152154
// call a wrapped function
@@ -162,7 +164,7 @@ describe('CaptureConsole setup', () => {
162164
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
163165
captureConsoleIntegration.setupOnce(
164166
() => undefined,
165-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
167+
() => getMockHubWithIntegration(captureConsoleIntegration),
166168
);
167169

168170
// call a wrapped function
@@ -181,7 +183,7 @@ describe('CaptureConsole setup', () => {
181183
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
182184
captureConsoleIntegration.setupOnce(
183185
() => undefined,
184-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
186+
() => getMockHubWithIntegration(captureConsoleIntegration),
185187
);
186188

187189
global.console.assert(1 + 1 === 3);
@@ -195,7 +197,7 @@ describe('CaptureConsole setup', () => {
195197
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
196198
captureConsoleIntegration.setupOnce(
197199
() => undefined,
198-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
200+
() => getMockHubWithIntegration(captureConsoleIntegration),
199201
);
200202

201203
global.console.assert(1 + 1 === 3, 'expression is false');
@@ -209,7 +211,7 @@ describe('CaptureConsole setup', () => {
209211
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
210212
captureConsoleIntegration.setupOnce(
211213
() => undefined,
212-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
214+
() => getMockHubWithIntegration(captureConsoleIntegration),
213215
);
214216

215217
global.console.assert(1 + 1 === 2);
@@ -219,7 +221,7 @@ describe('CaptureConsole setup', () => {
219221
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
220222
captureConsoleIntegration.setupOnce(
221223
() => undefined,
222-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
224+
() => getMockHubWithIntegration(captureConsoleIntegration),
223225
);
224226

225227
const someError = new Error('some error');
@@ -233,7 +235,7 @@ describe('CaptureConsole setup', () => {
233235
const captureConsoleIntegration = new CaptureConsole();
234236
captureConsoleIntegration.setupOnce(
235237
() => undefined,
236-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
238+
() => getMockHubWithIntegration(captureConsoleIntegration),
237239
);
238240

239241
const someError = new Error('some error');
@@ -247,7 +249,7 @@ describe('CaptureConsole setup', () => {
247249
const captureConsoleIntegration = new CaptureConsole();
248250
captureConsoleIntegration.setupOnce(
249251
() => undefined,
250-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
252+
() => getMockHubWithIntegration(captureConsoleIntegration),
251253
);
252254

253255
global.console.error('some message');
@@ -260,7 +262,7 @@ describe('CaptureConsole setup', () => {
260262
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
261263
captureConsoleIntegration.setupOnce(
262264
() => undefined,
263-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
265+
() => getMockHubWithIntegration(captureConsoleIntegration),
264266
);
265267

266268
global.console.error('some non-error message');
@@ -274,7 +276,7 @@ describe('CaptureConsole setup', () => {
274276
const captureConsoleIntegration = new CaptureConsole({ levels: ['info'] });
275277
captureConsoleIntegration.setupOnce(
276278
() => undefined,
277-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
279+
() => getMockHubWithIntegration(captureConsoleIntegration),
278280
);
279281

280282
global.console.info('some message');
@@ -292,7 +294,7 @@ describe('CaptureConsole setup', () => {
292294
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
293295
captureConsoleIntegration.setupOnce(
294296
() => undefined,
295-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
297+
() => getMockHubWithIntegration(captureConsoleIntegration),
296298
);
297299

298300
global.console.log('some message 1', 'some message 2');
@@ -308,11 +310,11 @@ describe('CaptureConsole setup', () => {
308310
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'someNonExistingLevel', 'error'] });
309311
captureConsoleIntegration.setupOnce(
310312
() => undefined,
311-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
313+
() => getMockHubWithIntegration(captureConsoleIntegration),
312314
);
313315

314316
// The provided level should not be created
315-
expect(global.console['someNonExistingLevel']).toBeUndefined();
317+
expect((global.console as any)['someNonExistingLevel']).toBeUndefined();
316318

317319
// Ohter levels should be wrapped as expected
318320
expect(global.console.log).not.toBe(originalConsole.log);
@@ -323,7 +325,7 @@ describe('CaptureConsole setup', () => {
323325
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'error'] });
324326
captureConsoleIntegration.setupOnce(
325327
() => undefined,
326-
() => getMockHubWithIntegration(null) as any, // simulate not having the integration registered
328+
() => getMockHubWithIntegration(null as any), // simulate not having the integration registered
327329
);
328330

329331
// Console should be wrapped
@@ -337,12 +339,12 @@ describe('CaptureConsole setup', () => {
337339

338340
it("should not crash when the original console methods don't exist at time of invocation", () => {
339341
const originalConsoleLog = global.console.log;
340-
global.console.log = undefined; // don't `delete` here, otherwise `fill` won't wrap the function
342+
global.console.log = undefined as any; // don't `delete` here, otherwise `fill` won't wrap the function
341343

342344
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
343345
captureConsoleIntegration.setupOnce(
344346
() => undefined,
345-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
347+
() => getMockHubWithIntegration(captureConsoleIntegration),
346348
);
347349

348350
expect(() => {

packages/integrations/test/extraerrordata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('ExtraErrorData()', () => {
7171
event = {
7272
// @ts-ignore Allow contexts on event
7373
contexts: {
74-
foo: 42,
74+
foo: { bar: 42 },
7575
},
7676
};
7777
const error = new TypeError('foo') as ExtendedError;
@@ -85,7 +85,7 @@ describe('ExtraErrorData()', () => {
8585
TypeError: {
8686
baz: 42,
8787
},
88-
foo: 42,
88+
foo: { bar: 42 },
8989
});
9090
});
9191

packages/integrations/test/offline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function initIntegration(options: { maxStoredEvents?: number } = {}): void {
169169
jest.spyOn(utils, 'getGlobalObject').mockImplementation(
170170
() =>
171171
({
172-
addEventListener: (_windowEvent, callback) => {
172+
addEventListener: (_windowEvent: any, callback: any) => {
173173
eventListeners.push(callback);
174174
},
175175
navigator: {

0 commit comments

Comments
 (0)