无法读取未定义的属性(读取“哨兵”)

问题描述 投票:0回答:1

在 Node.js 中使用 jest 和sentry-testkit 进行单元测试。 运行测试时出现错误 TypeError: Cannot readproperties of undefined (reading 'sentry')

import { describe, expect, it } from '@jest/globals';
import * as Sentry from '@sentry/node';
import sentryTestKit from 'sentry-testkit';

const { testkit, sentryTransport } = sentryTestKit();

Sentry.init({
  dsn: 'my-dsa',
  transport: sentryTransport,
});

describe('Sentry Test', () => {
  describe('Error Capture', () => {
    it('should be able to catch the error', () => {
      expect(testkit.reports()).toHaveLength(1);
    });
  });
});
node.js jestjs sentry
1个回答
-1
投票

我这样修复了错误:

import { init} from "@sentry/node";

init({
   dsn: 'my-dsa',
   transport: sentryTransport,
});
© www.soinside.com 2019 - 2024. All rights reserved.