在 ReactJS/Redux 应用程序中测试减速器时,如何向状态添加一些测试数据?
我有这个测试用例:
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”属性。当状态中没有任何内容时,上面的测试正在运行,因此会引发错误。如何在该特定测试用例的状态中添加测试数据?
感谢任何帮助
看起来您正在使用redux-testkit
. 根据文档,您可以使用withState
. 这是一个例子。
Reducer(filters)
.withState(state) // like this!
.expect(action)
.toReturnState(result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句