Skip to content

Commit

Permalink
assert on more things in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Oct 27, 2021
1 parent fd704f8 commit b2872a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/nextjs/test/index.client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseClient } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import * as SentryReact from '@sentry/react';
import { Integrations as TracingIntegrations } from '@sentry/tracing';
Expand All @@ -12,11 +13,12 @@ const { BrowserTracing } = TracingIntegrations;
const global = getGlobalObject();

const reactInit = jest.spyOn(SentryReact, 'init');
const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent');
const logError = jest.spyOn(logger, 'error');

describe('Client init()', () => {
afterEach(() => {
reactInit.mockClear();
jest.clearAllMocks();
global.__SENTRY__.hub = undefined;
});

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

const transaction = getCurrentHub().startTransaction({ name: '/404' });
const transaction = hub.startTransaction({ name: '/404' });
transaction.finish();

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

Expand Down
10 changes: 8 additions & 2 deletions packages/nextjs/test/index.server.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseClient } from '@sentry/core';
import { RewriteFrames } from '@sentry/integrations';
import * as SentryNode from '@sentry/node';
import { getCurrentHub, NodeClient } from '@sentry/node';
Expand All @@ -16,11 +17,12 @@ const global = getGlobalObject();
(global as typeof global & { __rewriteFramesDistDir__: string }).__rewriteFramesDistDir__ = '.next';

const nodeInit = jest.spyOn(SentryNode, 'init');
const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent');
const logError = jest.spyOn(logger, 'error');

describe('Server init()', () => {
afterEach(() => {
nodeInit.mockClear();
jest.clearAllMocks();
global.__SENTRY__.hub = undefined;
});

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

const transaction = getCurrentHub().startTransaction({ name: '/404' });
const transaction = hub.startTransaction({ name: '/404' });
transaction.finish();

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

Expand Down

0 comments on commit b2872a8

Please sign in to comment.