Skip to content

Commit b2872a8

Browse files
committed
assert on more things in tests
1 parent fd704f8 commit b2872a8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/nextjs/test/index.client.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BaseClient } from '@sentry/core';
12
import { getCurrentHub } from '@sentry/hub';
23
import * as SentryReact from '@sentry/react';
34
import { Integrations as TracingIntegrations } from '@sentry/tracing';
@@ -12,11 +13,12 @@ const { BrowserTracing } = TracingIntegrations;
1213
const global = getGlobalObject();
1314

1415
const reactInit = jest.spyOn(SentryReact, 'init');
16+
const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent');
1517
const logError = jest.spyOn(logger, 'error');
1618

1719
describe('Client init()', () => {
1820
afterEach(() => {
19-
reactInit.mockClear();
21+
jest.clearAllMocks();
2022
global.__SENTRY__.hub = undefined;
2123
});
2224

@@ -56,10 +58,14 @@ describe('Client init()', () => {
5658
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
5759
tracesSampleRate: 1.0,
5860
});
61+
const hub = getCurrentHub();
62+
const sendEvent = jest.spyOn(hub.getClient()!.getTransport!(), 'sendEvent');
5963

60-
const transaction = getCurrentHub().startTransaction({ name: '/404' });
64+
const transaction = hub.startTransaction({ name: '/404' });
6165
transaction.finish();
6266

67+
expect(sendEvent).not.toHaveBeenCalled();
68+
expect(captureEvent.mock.results[0].value).toBeUndefined();
6369
expect(logError).toHaveBeenCalledWith(new SentryError('An event processor returned null, will not send event.'));
6470
});
6571

packages/nextjs/test/index.server.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BaseClient } from '@sentry/core';
12
import { RewriteFrames } from '@sentry/integrations';
23
import * as SentryNode from '@sentry/node';
34
import { getCurrentHub, NodeClient } from '@sentry/node';
@@ -16,11 +17,12 @@ const global = getGlobalObject();
1617
(global as typeof global & { __rewriteFramesDistDir__: string }).__rewriteFramesDistDir__ = '.next';
1718

1819
const nodeInit = jest.spyOn(SentryNode, 'init');
20+
const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent');
1921
const logError = jest.spyOn(logger, 'error');
2022

2123
describe('Server init()', () => {
2224
afterEach(() => {
23-
nodeInit.mockClear();
25+
jest.clearAllMocks();
2426
global.__SENTRY__.hub = undefined;
2527
});
2628

@@ -93,10 +95,14 @@ describe('Server init()', () => {
9395
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
9496
tracesSampleRate: 1.0,
9597
});
98+
const hub = getCurrentHub();
99+
const sendEvent = jest.spyOn(hub.getClient()!.getTransport!(), 'sendEvent');
96100

97-
const transaction = getCurrentHub().startTransaction({ name: '/404' });
101+
const transaction = hub.startTransaction({ name: '/404' });
98102
transaction.finish();
99103

104+
expect(sendEvent).not.toHaveBeenCalled();
105+
expect(captureEvent.mock.results[0].value).toBeUndefined();
100106
expect(logError).toHaveBeenCalledWith(new SentryError('An event processor returned null, will not send event.'));
101107
});
102108

0 commit comments

Comments
 (0)