From 8e8b2312ac734702b63004cfc92c55c87d3f3ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 29 Apr 2021 14:41:56 +0200 Subject: [PATCH] test: Fix flaky onunhandledrejection tests --- .../node/test/onunhandledrejection.test.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/node/test/onunhandledrejection.test.ts b/packages/node/test/onunhandledrejection.test.ts index 7290db52c9ad..9118523cd289 100644 --- a/packages/node/test/onunhandledrejection.test.ts +++ b/packages/node/test/onunhandledrejection.test.ts @@ -1,15 +1,29 @@ -import { Hub, init, Integrations, Scope } from '../src'; +import { Scope } from '@sentry/core'; +import { Hub } from '@sentry/hub'; -const dsn = 'https://53039209a22b4ec1bcc296a3c9fdecd6@sentry.io/4291'; +import { OnUnhandledRejection } from '../src/integrations/onunhandledrejection'; + +jest.mock('@sentry/hub', () => { + // we just want to short-circuit it, so dont worry about types + const original = jest.requireActual('@sentry/hub'); + original.Hub.prototype.getIntegration = () => true; + return { + ...original, + getCurrentHub: () => new Hub(), + }; +}); describe('unhandled promises', () => { test('install global listener', () => { - init({ dsn }); + const integration = new OnUnhandledRejection(); + integration.setupOnce(); expect(process.listeners('unhandledRejection')).toHaveLength(1); }); test('sendUnhandledPromise', () => { - const integration = new Integrations.OnUnhandledRejection(); + const integration = new OnUnhandledRejection(); + integration.setupOnce(); + const promise = { domain: { sentryContext: {