Skip to content

Commit 35f9eb1

Browse files
authored
test: Fix flaky onunhandledrejection tests (#3482)
1 parent d5b335d commit 35f9eb1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/node/test/onunhandledrejection.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
import { Hub, init, Integrations, Scope } from '../src';
1+
import { Scope } from '@sentry/core';
2+
import { Hub } from '@sentry/hub';
23

3-
const dsn = 'https://[email protected]/4291';
4+
import { OnUnhandledRejection } from '../src/integrations/onunhandledrejection';
5+
6+
jest.mock('@sentry/hub', () => {
7+
// we just want to short-circuit it, so dont worry about types
8+
const original = jest.requireActual('@sentry/hub');
9+
original.Hub.prototype.getIntegration = () => true;
10+
return {
11+
...original,
12+
getCurrentHub: () => new Hub(),
13+
};
14+
});
415

516
describe('unhandled promises', () => {
617
test('install global listener', () => {
7-
init({ dsn });
18+
const integration = new OnUnhandledRejection();
19+
integration.setupOnce();
820
expect(process.listeners('unhandledRejection')).toHaveLength(1);
921
});
1022

1123
test('sendUnhandledPromise', () => {
12-
const integration = new Integrations.OnUnhandledRejection();
24+
const integration = new OnUnhandledRejection();
25+
integration.setupOnce();
26+
1327
const promise = {
1428
domain: {
1529
sentryContext: {

0 commit comments

Comments
 (0)