Skip to content

Commit ae1f4db

Browse files
committed
refactor tests
1 parent 7a93199 commit ae1f4db

File tree

2 files changed

+52
-69
lines changed

2 files changed

+52
-69
lines changed

packages/hub/test/hub.test.ts

Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ describe('Hub', () => {
2727
expect(hub.getStack()).toHaveLength(1);
2828
});
2929

30-
test.skip("don't invoke client sync with wrong func", () => {
31-
const hub = new Hub(clientFn);
32-
// @ts-ignore we want to able to call private method
33-
hub._invokeClient('funca', true);
34-
expect(clientFn).not.toHaveBeenCalled();
35-
});
36-
3730
test('isOlderThan', () => {
3831
const hub = new Hub();
3932
expect(hub.isOlderThan(0)).toBeFalsy();
@@ -194,113 +187,104 @@ describe('Hub', () => {
194187
});
195188

196189
describe('captureException', () => {
197-
test.skip('simple', () => {
198-
const hub = new Hub();
199-
const spy = jest.spyOn(hub as any, '_invokeClient');
190+
const mockClient: any = { captureException: jest.fn() };
191+
beforeEach(() => {
192+
mockClient.captureException.mockClear();
193+
});
194+
195+
test('simple', () => {
196+
const hub = new Hub(mockClient);
200197
hub.captureException('a');
201-
expect(spy).toHaveBeenCalled();
202-
expect(spy.mock.calls[0][0]).toBe('captureException');
203-
expect(spy.mock.calls[0][1]).toBe('a');
198+
expect(mockClient.captureException).toHaveBeenCalled();
199+
expect(mockClient.captureException.mock.calls[0][0]).toBe('a');
204200
});
205201

206-
test.skip('should set event_id in hint', () => {
207-
const hub = new Hub();
208-
const spy = jest.spyOn(hub as any, '_invokeClient');
202+
test('should set event_id in hint', () => {
203+
const hub = new Hub(mockClient);
209204
hub.captureException('a');
210-
// @ts-ignore Says mock object is type unknown
211-
expect(spy.mock.calls[0][2].event_id).toBeTruthy();
205+
expect(mockClient.captureException.mock.calls[0][1].event_id).toBeTruthy();
212206
});
213207

214-
test.skip('should generate hint if not provided in the call', () => {
215-
const hub = new Hub();
216-
const spy = jest.spyOn(hub as any, '_invokeClient');
208+
test('should generate hint if not provided in the call', () => {
209+
const hub = new Hub(mockClient);
217210
const ex = new Error('foo');
218211
hub.captureException(ex);
219-
// @ts-ignore Says mock object is type unknown
220-
expect(spy.mock.calls[0][2].originalException).toBe(ex);
221-
// @ts-ignore Says mock object is type unknown
222-
expect(spy.mock.calls[0][2].syntheticException).toBeInstanceOf(Error);
223-
// @ts-ignore Says mock object is type unknown
224-
expect(spy.mock.calls[0][2].syntheticException.message).toBe('Sentry syntheticException');
212+
expect(mockClient.captureException.mock.calls[0][1].originalException).toBe(ex);
213+
expect(mockClient.captureException.mock.calls[0][1].syntheticException).toBeInstanceOf(Error);
214+
expect(mockClient.captureException.mock.calls[0][1].syntheticException.message).toBe('Sentry syntheticException');
225215
});
226216
});
227217

228218
describe('captureMessage', () => {
229-
test.skip('simple', () => {
230-
const hub = new Hub();
231-
const spy = jest.spyOn(hub as any, '_invokeClient');
219+
const mockClient: any = { captureMessage: jest.fn() };
220+
beforeEach(() => {
221+
mockClient.captureMessage.mockClear();
222+
});
223+
224+
test('simple', () => {
225+
const hub = new Hub(mockClient);
232226
hub.captureMessage('a');
233-
expect(spy).toHaveBeenCalled();
234-
expect(spy.mock.calls[0][0]).toBe('captureMessage');
235-
expect(spy.mock.calls[0][1]).toBe('a');
227+
expect(mockClient.captureMessage).toHaveBeenCalled();
228+
expect(mockClient.captureMessage.mock.calls[0][0]).toBe('a');
236229
});
237230

238-
test.skip('should set event_id in hint', () => {
239-
const hub = new Hub();
240-
const spy = jest.spyOn(hub as any, '_invokeClient');
231+
test('should set event_id in hint', () => {
232+
const hub = new Hub(mockClient);
241233
hub.captureMessage('a');
242-
// @ts-ignore Says mock object is type unknown
243-
expect(spy.mock.calls[0][3].event_id).toBeTruthy();
234+
expect(mockClient.captureMessage.mock.calls[0][2].event_id).toBeTruthy();
244235
});
245236

246-
test.skip('should generate hint if not provided in the call', () => {
247-
const hub = new Hub();
248-
const spy = jest.spyOn(hub as any, '_invokeClient');
237+
test('should generate hint if not provided in the call', () => {
238+
const hub = new Hub(mockClient);
249239
hub.captureMessage('foo');
250-
// @ts-ignore Says mock object is type unknown
251-
expect(spy.mock.calls[0][3].originalException).toBe('foo');
252-
// @ts-ignore Says mock object is type unknown
253-
expect(spy.mock.calls[0][3].syntheticException).toBeInstanceOf(Error);
254-
// @ts-ignore Says mock object is type unknown
255-
expect(spy.mock.calls[0][3].syntheticException.message).toBe('foo');
240+
expect(mockClient.captureMessage.mock.calls[0][2].originalException).toBe('foo');
241+
expect(mockClient.captureMessage.mock.calls[0][2].syntheticException).toBeInstanceOf(Error);
242+
expect(mockClient.captureMessage.mock.calls[0][2].syntheticException.message).toBe('foo');
256243
});
257244
});
258245

259246
describe('captureEvent', () => {
260-
test.skip('simple', () => {
247+
const mockClient: any = { captureEvent: jest.fn() };
248+
beforeEach(() => {
249+
mockClient.captureEvent.mockClear();
250+
});
251+
252+
test('simple', () => {
261253
const event: Event = {
262254
extra: { b: 3 },
263255
};
264-
const hub = new Hub();
265-
const spy = jest.spyOn(hub as any, '_invokeClient');
256+
const hub = new Hub(mockClient);
266257
hub.captureEvent(event);
267-
expect(spy).toHaveBeenCalled();
268-
expect(spy.mock.calls[0][0]).toBe('captureEvent');
269-
expect(spy.mock.calls[0][1]).toBe(event);
258+
expect(mockClient.captureEvent).toHaveBeenCalled();
259+
expect(mockClient.captureEvent.mock.calls[0][0]).toBe(event);
270260
});
271261

272-
test.skip('should set event_id in hint', () => {
262+
test('should set event_id in hint', () => {
273263
const event: Event = {
274264
extra: { b: 3 },
275265
};
276-
const hub = new Hub();
277-
const spy = jest.spyOn(hub as any, '_invokeClient');
266+
const hub = new Hub(mockClient);
278267
hub.captureEvent(event);
279-
// @ts-ignore Says mock object is type unknown
280-
expect(spy.mock.calls[0][2].event_id).toBeTruthy();
268+
expect(mockClient.captureEvent.mock.calls[0][1].event_id).toBeTruthy();
281269
});
282270

283-
test.skip('sets lastEventId', () => {
271+
test('sets lastEventId', () => {
284272
const event: Event = {
285273
extra: { b: 3 },
286274
};
287-
const hub = new Hub();
288-
const spy = jest.spyOn(hub as any, '_invokeClient');
275+
const hub = new Hub(mockClient);
289276
hub.captureEvent(event);
290-
// @ts-ignore Says mock object is type unknown
291-
expect(spy.mock.calls[0][2].event_id).toEqual(hub.lastEventId());
277+
expect(mockClient.captureEvent.mock.calls[0][1].event_id).toEqual(hub.lastEventId());
292278
});
293279

294-
test.skip('transactions do not set lastEventId', () => {
280+
test('transactions do not set lastEventId', () => {
295281
const event: Event = {
296282
extra: { b: 3 },
297283
type: 'transaction',
298284
};
299-
const hub = new Hub();
300-
const spy = jest.spyOn(hub as any, '_invokeClient');
285+
const hub = new Hub(mockClient);
301286
hub.captureEvent(event);
302-
// @ts-ignore Says mock object is type unknown
303-
expect(spy.mock.calls[0][2].event_id).not.toEqual(hub.lastEventId());
287+
expect(mockClient.captureEvent.mock.calls[0][1].event_id).not.toEqual(hub.lastEventId());
304288
});
305289
});
306290

packages/minimal/test/lib/minimal.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { getCurrentHub, getHubFromCarrier, Scope } from '@sentry/hub';
22
import { Severity } from '@sentry/types';
33

44
import {
5-
_callOnClient,
65
captureEvent,
76
captureException,
87
captureMessage,

0 commit comments

Comments
 (0)