Javascript 使用Microsoft application insights React插件进行React app Jest单元测试失败

Javascript 使用Microsoft application insights React插件进行React app Jest单元测试失败,javascript,reactjs,unit-testing,jestjs,azure-application-insights,Javascript,Reactjs,Unit Testing,Jestjs,Azure Application Insights,我正在尝试在我的React应用程序中使用Microsoft的Application Insights JavaScript SDK React插件,尽管它工作成功,但我在通过Jest和Ezyme单元测试时遇到了困难 我已按如下方式设置了单元测试: import React from 'react'; import {act} from 'react-dom/test-utils'; import ReactDOM from 'react-dom'; import App from '../App

我正在尝试在我的React应用程序中使用Microsoft的Application Insights JavaScript SDK React插件,尽管它工作成功,但我在通过Jest和Ezyme单元测试时遇到了困难

我已按如下方式设置了单元测试:

import React from 'react';
import {act} from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import App from '../App.view';

jest.mock('@microsoft/applicationinsights-react-js', () => ({
  ReactPlugin: Object,
}));

jest.mock('@microsoft/applicationinsights-web', () => ({
  ApplicationInsights: Object,
  loadAppInsights: () => ({}),
}));

describe('App View', () => {
  it('renders without crashing', () => {
    const div = document.createElement('div');
    act(() => {
      ReactDOM.render(<App />, div);
    });
    ReactDOM.unmountComponentAtNode(div);
  });
});
当我运行测试时,我不断得到错误,
TypeError:ai.loadAppInsights不是一个函数

由于我正在对ApplicationInsights模块使用jest mock,所以我也尝试了几种方法来模拟这个方法,但没有成功。你知道我遗漏了什么吗?我也找不到任何关于如何将应用程序洞察正确集成到React应用程序的好文档,其中包括正确的单元测试

提前谢谢

import {ApplicationInsights} from '@microsoft/applicationinsights-web';
import {ReactPlugin, withAITracking} from '@microsoft/applicationinsights-react-js';
import {createBrowserHistory} from 'history';

// Set up AppInsights connection
const browserHistory = createBrowserHistory({basename: ''});
const reactPlugin = new ReactPlugin();
const ai = new ApplicationInsights({
  config: {
    instrumentationKey:
      process.env.REACT_APP_APPINSIGHTS_KEY || 'xxxxxxxxxxx-xxxxxxxxxx-xxxxxxx-xxxxx',
    extensions: [reactPlugin],
    extensionConfig: {
      [reactPlugin.identifier]: {history: browserHistory},
    },
  },
});
ai.loadAppInsights();

export default Component => withAITracking(reactPlugin, Component);
export const appInsights = ai.appInsights;