我正在尝试使用 Jest 使用Redux ( react-redux+ reduxsauce)测试 React 应用程序。我实施了以下方法:
import { createActions, createReducer } from "reduxsauce";
/**
* Action types & creators
*/
export const { Types, Creators } = createActions({
addSample: ["text"],
removeSample: ["id"]
});
/**
* Handlers
*/
export const INITIAL_STATE = [];
export function add(state = INITIAL_STATE, action) {
return [...state, { id: Math.random(), text: action.text }];
}
export function remove(state = INITIAL_STATE, action) {
return state.filter(sample => sample.id !== action.id);
}
/**
* Reducer
*/
export default createReducer(INITIAL_STATE, {
[Types.ADD_SAMPLE]: add,
[Types.REMOVE_SAMPLE]: remove
});
这个实现允许我在组件之间使用 Redux 存储。但是,在测试中我无法达到 100% 的覆盖率,因为仅在分支的标准中我是覆盖率 0%(在其他标准中我达到 100% - 语句、函数、行);在 Coverage 的反馈中指出,在第 16 行和第 20 行,我没有对 Handlersadd()和remove().
我想在内部reduxsauce实现了一些 Reducer switch case,但我不知道如何测试这部分方式允许测试覆盖标准
HUH函数
富国沪深
随时随地看视频慕课网APP
相关分类