8000 test: Ensure withScope and run bubble up exceptions (#3764) · jcomo/sentry-javascript@a904415 · GitHub
[go: up one dir, main page]

Skip to content

Commit a904415

Browse files
authored
test: Ensure withScope and run bubble up exceptions (getsentry#3764)
The new tests just emphasize and guarantee the current behavior.
1 parent 3f53fef commit a904415

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

packages/hub/test/hub.test.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,20 @@ describe('Hub', () => {
121121
});
122122

123123
describe('withScope', () => {
124+
let hub: Hub;
125+
126+
beforeEach(() => {
127+
hub = new Hub();
128+
});
129+
124130
test('simple', () => {
125-
const hub = new Hub();
126131
hub.withScope(() => {
127132
expect(hub.getStack()).toHaveLength(2);
128133
});
129134
expect(hub.getStack()).toHaveLength(1);
130135
});
131136

132137
test('bindClient', () => {
133-
const hub = new Hub();
134138
const testClient: any = { bla: 'a' };
135139
hub.withScope(() => {
136140
hub.bindClient(testClient);
@@ -139,6 +143,15 @@ describe('Hub', () => {
139143
});
140144
expect(hub.getStack()).toHaveLength(1);
141145
});
146+
147+
test('should bubble up exceptions', () => {
148+
const error = new Error('test');
149+
expect(() => {
150+
hub.withScope(() => {
151+
throw error;
152+
});
153+
}).toThrow(error);
154+
});
142155
});
143156

144157
test('getCurrentClient', () => {
@@ -277,18 +290,30 @@ describe('Hub', () => {
277290
expect(eventId).toBe(hub.lastEventId());
278291
});
279292

280-
test('run', () => {
281-
const currentHub = getCurrentHub();
282-
const myScope = new Scope();
283-
const myClient: any = { a: 'b' };
284-
myScope.setExtra('a', 'b');
285-
const myHub = new Hub(myClient, myScope);
286-
myHub.run(hub => {
287-
expect(hub.getScope()).toBe(myScope);
288-
expect(hub.getClient()).toBe(myClient);
289-
expect(hub).toBe(getCurrentHub());
293+
describe('run', () => {
294+
test('simple', () => {
295+
const currentHub = getCurrentHub();
296+
const myScope = new Scope();
297+
const myClient: any = { a: 'b' };
298+
myScope.setExtra('a', 'b');
299+
const myHub = new Hub(myClient, myScope);
300+
myHub.run(hub => {
301+
expect(hub.getScope()).toBe(myScope);
302+
expect(hub.getClient()).toBe(myClient);
303+
expect(hub).toBe(getCurrentHub());
304+
});
305+
expect(currentHub).toBe(getCurrentHub());
306+
});
307+
308+
test('should bubble up exceptions', () => {
309+
const hub = new Hub();
310+
const error = new Error('test');
311+
expect(() => {
312+
hub.run(() => {
313+
throw error;
314+
});
315+
}).toThrow(error);
290316
});
291-
expect(currentHub).toBe(getCurrentHub());
292317
});
293318

294319
describe('breadcrumbs', () => {

0 commit comments

Comments
 (0)
0