Skip to content

Commit accf2ac

Browse files
committed
add suggested tests
1 parent d53dea3 commit accf2ac

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/tracing/test/hub.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ describe('Hub', () => {
178178
expect(tracesSampler).toHaveBeenCalled();
179179
});
180180

181+
it('should set sampled = false if tracesSampler returns 0', () => {
182+
const tracesSampler = jest.fn().mockReturnValue(0);
183+
const hub = new Hub(new BrowserClient({ tracesSampler }));
184+
const transaction = hub.startTransaction({ name: 'dogpark' });
185+
186+
expect(tracesSampler).toHaveBeenCalled();
187+
expect(transaction.sampled).toBe(false);
188+
});
189+
190+
it('should set sampled = true if tracesSampler returns 1', () => {
191+
const tracesSampler = jest.fn().mockReturnValue(1);
192+
const hub = new Hub(new BrowserClient({ tracesSampler }));
193+
const transaction = hub.startTransaction({ name: 'dogpark' });
194+
195+
expect(tracesSampler).toHaveBeenCalled();
196+
expect(transaction.sampled).toBe(true);
197+
});
198+
181199
it('should prefer tracesSampler to tracesSampleRate', () => {
182200
// make the two options do opposite things to prove precedence
183201
const tracesSampler = jest.fn().mockReturnValue(true);

0 commit comments

Comments
 (0)