我正在阅读并练习教程:http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html 但我无法通过减速机测试。然后我做了一个新的测试,找出原因。
这是test.js(带chai的摩卡):
import {expect} from 'chai';
import {List, Map, fromJS} from 'immutable';
describe('set', () => {
it('sets map\'s property', () => {
const state = Map();
const action = {type: 'SET_ENTRIES', entries: ['Trainspotting']};
const nextState = state.set('entries', action.entries);
/*
expect(nextState).to.equal(Map({
entries: ['Trainspotting']
}));
*/
expect(nextState).to.equal(fromJS({
entries: ['Trainspotting']
}));
});
});
使用Map或fromJS,测试不通过
如果选择“地图”,则会显示:
AssertionError: expected 'Map { "entries": Trainspotting }' to equal 'Map { "entries": Trainspotting }'
+ expected - actual
如果选择“fromJS”,则会显示:
AssertionError: expected 'Map { "entries": Trainspotting }' to equal 'Map { "entries": List [ "Trainspotting" ] }'
+ expected - actual
-Map { "entries": Trainspotting }
+Map { "entries": List [ "Trainspotting" ] }
这真令人困惑。如何使它工作?
答案 0 :(得分:0)
你试过吗
const nextState = state.set('entries', List(action.entries));