我正在尝试执行简单的减速器测试。新的开始加载();调度这应该将 isLoading 设置为 true。不幸的是,它显示: 预期 $.isLoading = false 等于 true。
没有什么花哨。这是测试的样子:
it('should set isLoading to true', () => {
const isLoading = true;
const action = new StartLoading();
const newState = uiReducers(initialState, action);
const expectedState = { ...initialState, isLoading };
expect(newState).toEqual(expectedState);
})
和减速机:
export interface UIState {
isLoading: boolean;
}
export const initialState: UIState = {
isLoading: false
};
export function uiReducers(state = initialState, action: UIActions) {
switch (action.type) {
case UIActionTypes.START_LOADING: {
console.log('stt')
return {
isLoading: true,
...state
};
}
case UIActionTypes.STOP_LOADING: {
return {
isLoading: false,
...state
};
}
default:
return {
...state
}
}
}