Dispatcher在jest单元测试中没有注册回调。

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

非常类似于 Dispatcher在jest单元测试中没有注册回调。

我在真实的商店里有dispatcher.register,在我的jest单元测试中,模拟的dispatcher没有注册任何回调。在我的jest单元测试中,模拟的dispatcher没有注册任何回调。我是否遗漏了什么,请告诉我。

describe(“Simple store tests",function(){
    var actionTypes = require('../../constants/actionTypes');
    var AppDispatcher, simpleStore, callback;
//mock action
    var getProjects = {actionType: actionTypes.actions.GET_PROJECTS};
//prepare
    AppDispatcher = require('../../dispatcher/AppDispatcher');
    simpleStore = require('../simpleStore');
    var simpleActions = require('../../actions/simpleActions');

//callback = AppDispatcher.register.mock.calls[0][0];       //this one fails

    it('should initialize with no projects in the list',function(){
        var projects = simpleActions.getProjects();
        console.log(AppDispatcher.register.mock.calls.length); *//this comes back as zero*
    })

})
reactjs-flux jestjs
1个回答
0
投票

你有没有告诉Jest不要模拟你的测试中的商店?另外,如果您使用的是 object-assign 在你的商店里,你也应该告诉jest不要嘲讽这一点。

在你的测试顶部--在你第一次调用描述之前--添加这几行,希望能起到作用。

jest.dontMock('../simpleStore');
jest.dontMock('object-assign'); // only if using object-assign

describe('simple store tests', function() {
    // rest of your code as before
});
© www.soinside.com 2019 - 2024. All rights reserved.