我已經使用節點/終極版,我已經同時用柴測試以下:不可改變柴斷言錯誤而預期的equals導致
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()
和.to.deep.equal()
。 感謝您的幫助。
您應該將此答案標記爲解決您的問題,因爲這確實是問題:) – astorije