2016-12-06 142 views
0

我在一个教程第二个参数是什么?

... 
import configureMockStore from 'redux-mock-store'; 

const middleware = [thunk]; 
const mockStore = configureMockStore(middleware); 
... 

it('should create BEGIN_AJAX_CALL & LOAD_COURSES_SUCCESS', (done) => { 

    const expectedActions = [ 
     {type: types.BEGIN_AJAX_CALL}, 
     {type: types.LOAD_COURSES_SUCCESS, body: { 
      courses: [{id:'clean-code', title:'Clean Code'}] 
     }} 
    ]; 

    const store = mockStore({courses:[]}, expectedActions); 

    store 
     .dispatch(courseActions.loadCourses()) 
     .then(() => { 
      const actions = store.getActions(); 
      expect(actions[0].type).toEqual(types.BEGIN_AJAX_CALL); 
      expect(actions[1].type).toEqual(types.LOAD_COURSES_SUCCESS); 
      done(); 
     }); 
}); 

expectedActions整个位没有意义发现这个代码。

文档说,如果有第二个参数给store,它应该是一个功能; (没有解释告诉那个函数会做什么)。

起初我以为它出于某种原因强迫某些行为进入商店,但快速console.log告诉我,情况并非如此。

因为只有dispatch会导致动作累积。

那么,在文本中还是一些智慧中进一步探索是错误的?

+0

Rob ... re:标题编辑。当人们搜索“redux-mock-store second argument”时,Google是否会立即找到我的问题?没有好的结果,这个问题将是第一个。 – dwilbank

回答

0

此功能在版本1中已删除,但您可以在1 docs之前找到该示例。

参数expectedActions用于测试。您可以使用一系列操作创建一个模拟商店,然后发送第一个操作。这一行动将导致其他其他措施以转发(派遣一个/下)通过的thunk/API中间件的/ etc ...测试将检查所有的expectedActions阵列中的操作都作用于实体店:

import configureStore from 'redux-mock-store'; 

    const middlewares = []; // add your middlewares like `redux-thunk` 
    const mockStore = configureStore(middlewares); 

    // Test in mocha 
    it('should dispatch action', (done) => { 
     const getState = {}; // initial state of the store 
     const action = { type: 'ADD_TODO' }; 
     const expectedActions = [action]; 

     const store = mockStore(getState, expectedActions, done); 
     store.dispatch(action); 
    }) 
+0

谢谢。我可以看到它被删除的原因。混乱! – dwilbank

相关问题