而我正在嘗試爲redux reducer做單元測試。但我正在努力接受相同的預期和相同的結果。Redux reducer單元測試
const initState = {};
export default function (state = initState, action) {
const newState = { ...state };
switch (action.type) {
case CREATE_TYPE:
return {
...state,
[action.customType.id]: {
...action.customType
}
};
default:
return state;
}
}
我的測試。似乎在customType: { id: 'test-id' }
describe('reducer',() => {
it('should return the initial state',() => {
const state = reducer(undefined, { type: 'unknown' });
expect(state).toEqual({});
});
it('should handle CREATE_TYPE',() => {
expect(reducer({ test: true }, {
type: CREATE_TYPE,
customType: { id: 'test-id' },
id: 'test-id'
})).toEqual({
'test-id': 'test-type',
'test': true
});
});
});