我一直在使用 node/redux 并且在使用 chai 进行测试时我有以下内容:
AssertionError: expected 'Map { "winos": List [ Map { "id": 1, "x": 1, "y": 1, "movable": false }, Map { "id": 2, "x": 2, "y": 2, "movable": false }, Map { "id": 5, "x": 5, "y": 5, "movable": false } ] }'
to equal 'Map { "winos": List [ Map { "id": 1, "x": 1, "y": 1, "movable": false }, Map { "id": 2, "x": 2, "y": 2, "movable": false }, Map { "id": 5, "x": 5, "y": 5, "movable": false } ] }'
我已经看到这是一个已知错误:https ://github.com/astorije/chai-immutable/issues/24 。那里的人设法通过使树中的所有内容不可变来解决这个问题,但我认为我已经拥有不可变的所有内容。
我的代码如下:
import {List, Map} from 'immutable';
import {expect} from 'chai';
export function addWino(state, wino) {
return state.updateIn(['winos'], arr => arr.push(wino));
}
describe('setWinos', () => {
describe('addWino', () => {
it('adds a Wino', () => {
const wino = Map({
id: 5,
x:5,
y:5,
movable: false
});
const nextState = addWino(state, wino);
expect(nextState).to.equal(Map({
winos: List.of([
Map({
id: 1,
x:1,
y:1,
movable: false
})
],
[
Map({
id: 2,
x:2,
y:2,
movable: false
})
],
[
Map({
id: 5,
x:5,
y:5,
movable: false
})
])
}));
});
});
}
我也已经尝试过.eql()
and .to.deep.equal()
。谢谢你的帮助。