You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

组件单元测试中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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 15:00:29