Skip to content

Commit 898dd30

Browse files
committed
add tests for manual startTransaction
1 parent a478689 commit 898dd30

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/hub/test/exports.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
setTag,
1111
setTags,
1212
setUser,
13+
startTransaction,
1314
withScope,
1415
} from '../src/exports';
1516

@@ -184,6 +185,35 @@ describe('Top Level API', () => {
184185
});
185186
});
186187

188+
describe('startTransaction', () => {
189+
beforeEach(() => {
190+
global.__SENTRY__ = {
191+
hub: undefined,
192+
extensions: {
193+
startTransaction: (context: any) => ({
194+
name: context.name,
195+
// Spread rather than assign in case it's undefined
196+
metadata: { ...context.metadata },
197+
}),
198+
},
199+
};
200+
});
201+
202+
it("sets source to `'custom'` if no source provided", () => {
203+
const transaction = startTransaction({ name: 'dogpark' });
204+
205+
expect(transaction.name).toEqual('dogpark');
206+
expect(transaction.metadata.source).toEqual('custom');
207+
});
208+
209+
it('uses given `source` value', () => {
210+
const transaction = startTransaction({ name: 'dogpark', metadata: { source: 'route' } });
211+
212+
expect(transaction.name).toEqual('dogpark');
213+
expect(transaction.metadata.source).toEqual('route');
214+
});
215+
});
216+
187217
test('Clear Scope', () => {
188218
const client: any = new TestClient({});
189219
getCurrentHub().withScope(() => {

0 commit comments

Comments
 (0)