Skip to content

Commit 712feb2

Browse files
committed
add tests
1 parent 3067925 commit 712feb2

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

packages/core/src/baseclient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
360360
* @inheritDoc
361361
*/
362362
public on(hook: HookName, callback: HookCallback): void {
363-
if (this._hooks[hook]) {
364-
// @ts-ignore we cannot enforce the callback to match the hook
365-
// while saving bundle size
366-
this._hooks[hook].push(callback);
367-
} else {
363+
if (!this._hooks[hook]) {
368364
this._hooks[hook] = [];
369365
}
366+
367+
// @ts-ignore we cannot enforce the callback to match the hook
368+
// while saving bundle size
369+
this._hooks[hook].push(callback);
370370
}
371371

372372
/**

packages/core/test/lib/base.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Event, Span } from '@sentry/types';
1+
import type { Event, Span, Transaction } from '@sentry/types';
22
import { dsnToString, logger, SentryError, SyncPromise } from '@sentry/utils';
33

44
import { Hub, makeSession, Scope } from '../../src';
@@ -1730,4 +1730,23 @@ describe('BaseClient', () => {
17301730
expect(clearedOutcomes4.length).toEqual(0);
17311731
});
17321732
});
1733+
1734+
describe('hooks', () => {
1735+
it('should call a startTransaction hook', () => {
1736+
expect.assertions(1);
1737+
1738+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
1739+
const client = new TestClient(options);
1740+
1741+
let mockTransaction = {
1742+
traceId: '86f39e84263a4de99c326acab3bfe3bd',
1743+
} as Transaction;
1744+
1745+
client.on('startTransaction', (transaction: Transaction) => {
1746+
expect(transaction).toEqual(mockTransaction);
1747+
});
1748+
1749+
client.emit('startTransaction', mockTransaction);
1750+
});
1751+
});
17331752
});

0 commit comments

Comments
 (0)