【发布时间】:2019-02-19 13:58:35
【问题描述】:
在我的 ReactJS/Redux 应用程序中测试 reducer 时,如何向 state 添加一些测试数据?
我有这个测试用例:
it("should store selected filter", () => {
const selectedFilterData = {
id: 4321,
filterGroupId: 1234,
filterName: "gender",
text: "Male",
value: "pdl_profile_gender_1"
}
const action = { type: FILTER_SELECTED, data: selectedFilterData }
Reducer(filters).expect(action).toReturnState({
1234: {
id: 1234,
selectedFilters: [
{
id: 4321,
filterName: "gender",
text: "Male",
value: "pdl_profile_gender_1"
}
]
}
})
})
此操作/reducer 更新对应 ID 的现有“selectedFilters”属性。当状态中没有任何内容时,上述测试正在运行,因此会引发错误。如何在该特定测试用例的状态中添加测试数据?
感谢任何帮助
【问题讨论】:
标签: reactjs unit-testing redux jestjs