设置一个 属性 的 Map 后的困惑
Confusion after setting a property of a Map
我正在阅读和练习教程:http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html
但是我无法通过 reducer 测试。然后我又做了一个新的测试来找出原因。
这是test.js(加柴的摩卡咖啡):
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,测试都不通过
如果选择"Map",则显示:
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" ] }
真让人费解。如何让它发挥作用?
你尝试了吗
const nextState = state.set('entries', List(action.entries));
我正在阅读和练习教程:http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html 但是我无法通过 reducer 测试。然后我又做了一个新的测试来找出原因。
这是test.js(加柴的摩卡咖啡):
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,测试都不通过
如果选择"Map",则显示:
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" ] }
真让人费解。如何让它发挥作用?
你尝试了吗
const nextState = state.set('entries', List(action.entries));