Javascript 如何存根一个独立导出的助手方法

Javascript 如何存根一个独立导出的助手方法,javascript,reactjs,unit-testing,sinon-chai,Javascript,Reactjs,Unit Testing,Sinon Chai,我有一个叫做Dashboard的组件。在componentDidMount生命周期方法中,我调用了一个异步助手方法。现在,在我的单元测试中,我试图存根相同的方法来验证方法调用和响应 在安装组件之前,我已经尝试了sinon.stub的存根方法 import React from 'react'; import { getEvents} from '../actions'; class Dashboard extends React.Component { //constructor compon

我有一个叫做Dashboard的组件。在componentDidMount生命周期方法中,我调用了一个异步助手方法。现在,在我的单元测试中,我试图存根相同的方法来验证方法调用和响应

在安装组件之前,我已经尝试了sinon.stub的存根方法

import React from 'react';
import { getEvents} from '../actions';
class Dashboard extends React.Component {
//constructor 
componentDidMount() {
    getEvents().then(response => {
      //does something
    });
//other methods
}

import*作为来自“../../actions”的操作;
从“sinon”进口sinon;
从“../index”导入仪表板;
从“酶”导入{mount};
从“chai”导入{expect};
描述('测试仪表板',()=>{
它('should call get events helper method',()=>{
const stub=sinon.stub(actions,'getEvents')。返回(Promise.resolve({}));
const wrapper=mount();
expect(stub).to.have.property('callCount',1);
})
})
断言失败,调用计数为零

import * as actions from '../../actions';
import sinon from 'sinon';
import Dashboard from '../index';
import { mount } from 'enzyme';
import { expect } from 'chai';

describe('testing dashboard', () => {
it('should call get events helper method', () => {
const stub = sinon.stub(actions, 'getEvents').returns(Promise.resolve({}));
const wrapper = mount(<Dashboard/>);

expect(stub).to.have.property('callCount', 1);
})
})