Skip to content

Commit

Permalink
test: Ensure withScope and run bubble up exceptions (#3764)
Browse files Browse the repository at this point in the history
The new tests just emphasize and guarantee the current behavior.
  • Loading branch information
rhcarvalho authored Jun 29, 2021
1 parent 3f53fef commit a904415
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions packages/hub/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,20 @@ describe('Hub', () => {
});

describe('withScope', () => {
let hub: Hub;

beforeEach(() => {
hub = new Hub();
});

test('simple', () => {
const hub = new Hub();
hub.withScope(() => {
expect(hub.getStack()).toHaveLength(2);
});
expect(hub.getStack()).toHaveLength(1);
});

test('bindClient', () => {
const hub = new Hub();
const testClient: any = { bla: 'a' };
hub.withScope(() => {
hub.bindClient(testClient);
Expand All @@ -139,6 +143,15 @@ describe('Hub', () => {
});
expect(hub.getStack()).toHaveLength(1);
});

test('should bubble up exceptions', () => {
const error = new Error('test');
expect(() => {
hub.withScope(() => {
throw error;
});
}).toThrow(error);
});
});

test('getCurrentClient', () => {
Expand Down Expand Up @@ -277,18 +290,30 @@ describe('Hub', () => {
expect(eventId).toBe(hub.lastEventId());
});

test('run', () => {
const currentHub = getCurrentHub();
const myScope = new Scope();
const myClient: any = { a: 'b' };
myScope.setExtra('a', 'b');
const myHub = new Hub(myClient, myScope);
myHub.run(hub => {
expect(hub.getScope()).toBe(myScope);
expect(hub.getClient()).toBe(myClient);
expect(hub).toBe(getCurrentHub());
describe('run', () => {
test('simple', () => {
const currentHub = getCurrentHub();
const myScope = new Scope();
const myClient: any = { a: 'b' };
myScope.setExtra('a', 'b');
const myHub = new Hub(myClient, myScope);
myHub.run(hub => {
expect(hub.getScope()).toBe(myScope);
expect(hub.getClient()).toBe(myClient);
expect(hub).toBe(getCurrentHub());
});
expect(currentHub).toBe(getCurrentHub());
});

test('should bubble up exceptions', () => {
const hub = new Hub();
const error = new Error('test');
expect(() => {
hub.run(() => {
throw error;
});
}).toThrow(error);
});
expect(currentHub).toBe(getCurrentHub());
});

describe('breadcrumbs', () => {
Expand Down

0 comments on commit a904415

Please sign in to comment.