与Dispatcher not registering callbacks in jest unit tests非常相似
我在实体店有dispatcher.register。在我的jest单元测试中,模拟调度程序没有注册任何回调。我在这里错过了什么吗?请告诉我..
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*
})
})
答案 0 :(得分:0)
你有没有告诉开玩笑不要嘲笑你的商店?此外,如果您在商店中使用object-assign
,您也应该开玩笑说不要嘲笑它。
在第一次调用描述之前,在测试的顶部添加这些行 - 希望能够做到这一点:
jest.dontMock('../simpleStore');
jest.dontMock('object-assign'); // only if using object-assign
describe('simple store tests', function() {
// rest of your code as before
});
希望这有帮助。