Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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