组件单元测试中Mock Store数据无法传入组件导致测试失败的问题求助
组件单元测试中Mock Store数据无法传入组件导致测试失败的问题求助
我正在为组件里的计算逻辑编写单元测试,但遇到了个棘手的问题:我已经创建了mockStore,可里面的数据就是没法传到组件中,直接导致我的测试用例一直失败。
下面是我的mockStore代码:
import { configureStore } from '@reduxjs/toolkit'; import { creditStatementData } from './__mock__Data/mockCreditStatement.json'; // Adjust the path as needed const initialState = { creditStatementList: creditStatementData, }; // Reducer function const creditStatementListReducer = (state = initialState, action) => { switch (action.type) { // You can add cases for any actions you may want to test default: return state.creditStatementList || []; // Return the state as is for any other action } }; // Configure the mock store const mockStore = configureStore({ reducer: { creditStatementList: creditStatementListReducer, }, preloadedState: initialState, }); export default mockStore;
有没有大佬能帮我排查下问题出在哪?怎么才能让mockStore里的数据正常传递到组件中,让测试用例顺利通过呢?
备注:内容来源于stack exchange,提问作者Chandru Logan
相关产品推荐
相关产品推荐

