2017-10-10 57 views
0

我需要编写单元测试以帮助下面的Redux操作。 在Google中,我看到了一些示例,但他们编写动作的方式似乎有很大不同,所以我在为Redux动作编写单元测试时面临一些困难。Redux Action Unit Testing(Mocha&Chai)

下面是终极版的行动,我有:

import * as types from './readerTypes'; 
 

 
export const documentSuccessAction = (data) => { 
 
    return (dispatch, getState) => { 
 
    dispatch({ 
 
     type: 'GET_METADATA_SUCCESS', 
 
     metadata: data.document 
 
    }); 
 

 
    dispatch({ 
 
     type: 'GET_DOCUMENT_SUCCESS', 
 
     document : data.documentContent 
 
    }); 
 
    }; 
 
}; 
 

 
export const getDocument = (docID) => { 
 
    return (dispatch, getState) => dispatch({ 
 
    type: 'API_REQUEST', 
 
    options: { 
 
     method: 'GET', 
 
     service: 'reader', 
 
     endpoint: `document/${docID}`, 
 
     actionTypes: { 
 
     loading: 'GET_DOCUMENT_LOADING', 
 
     success: documentSuccessAction, 
 
     error: 'GET_DOCUMENT_ERROR' 
 
     } 
 
    } 
 
    }); 
 
};

任何人都可以请帮我这个?

谢谢

+0

你有什么样的困难?你有什么尝试,什么不工作,请详细说明。 – cinnaroll45

回答

相关问题