1
我學習終極版測試問題作出反應終極版,我使用的是TDD目前正在實施一些減速。我正在使用一個示例應用程序,它只是一個用於添加/刪除/打開/關閉筆記的記事本。與柴
我正在做一些測試添加新的筆記,但第二個「它」失敗,則拋出我的錯誤是:
1)AddNote減速應返回兩個注意事項: 的AssertionError :預期{對象(ID-123,ID-456)}等於{對象(byId,IDS,...)}
describe('AddNote reducer' ,() => {
it('should return a new note',() => {
const state = getMockState.withNoNotes();
const actualNextState = reducers.byId(
state.byId, actions.addNote(
'Hello World', 'id-123', 1));
const expectedNextState = {
'id-123': {
id: 'id-123',
content: 'Hello World',
timestamp: 1
}
};
expect(actualNextState).to.deep.equal(expectedNextState);
});
it('should return two notes',() => {
const state = getMockState.withOneNote();
const actualNextState = reducers.byId(state.byId, actions.addNote('Bye bye world!', 'id-456', 2));
const expectedNextState = {
...state,
'id-456': {
id: 'id-456',
content: 'Bye bye world!',
timestamp: 2
}
};
expect(actualNextState).to.deep.equal(expectedNextState);
});
});
我使用也是一個幫手,這裏是
export const getMockState = {
withNoNotes:() => ({
byId: {},
ids: [],
openNoteId: null,
}),
withOneNote:() => ({
byId: {
'id-123': {
id: 'id-123',
content: 'Hello world',
timestamp: 1,
},
},
ids: ['id-123'],
openNoteId: 'id-123',
}),
};
的想法是,如果我在它會返回一個新的狀態,只是記下第一種情況下添加備註,但在第二種情況下,它應該與以前的筆記,再加上新的返回狀態。 我使用柴期望圖書館與摩卡。
如果它幫助這裏的狀態的輸出(這是一個控制檯日誌),我認爲這是好的,
{ 'id-123': { id: 'id-123', content: 'Hello World', timestamp: 1 } }
√ should return a new note
{ 'id-123': { id: 'id-123', content: 'Hello world', timestamp: 1 },
'id-456': { id: 'id-456', content: 'Bye bye world!', timestamp: 2 } }
1) should return two notes
這裏的是我的減速器
import { merge } from 'ramda';
export const byId = (state={}, {type, payload}) => {
switch(type) {
case 'app/addNote':
console.log(merge(state, { [payload.id]: payload})) ;
return merge(state, { [payload.id]: payload});
default:
return state;
}
};
任何想法?提前致謝!