1
我試圖拿起Redux,以下教程使用ImmutableJs。我對ImmutableJs完全陌生,我只是想通過API文檔來開始。我的練習應用比教程複雜得多,所以我走了一段路,可能已經迷路了。Immutablejs Map.update打破單元測試
任何時候我使用Map.update()方法,我無法找到成功測試我的代碼的方法。下面是測試我寫試圖弄清楚什麼是錯的:
import chai, {expect} from 'chai';
import chaiImmutable from 'chai-immutable';
import {List, Map} from 'immutable';
chai.use(chaiImmutable);
describe("Immutable Test Issues",() => {
it("should present accurate immutable equality",() => {
// -- Maps with Lists match just fine
const a1 = Map({ test: 1, args: List([1, 2]) });
const a2 = Map({ test: 1, args: List([1, 2]) });
expect(a1).to.equal(a2); // pass
// -- Maps with Lists of Maps match just fine
const ba = { pid: 100, arg: 2 };
const bb = { pid: 101, arg: 5 };
const b1 = Map({ test: 1, args: List([Map(ba), Map(bb)]) });
const b2 = Map({ test: 1, args: List([Map(ba), Map(bb)]) });
expect(b1).to.equal(b2); // pass
// -- using Map.update()
const ea = { pid: 100, arg: 2 };
const eb = { pid: 101, arg: 4 };
const e1 = Map({ test: 1 }).update('args', List(), l => l.push([Map(ea), Map(eb)]));
const e2 = Map({ test: 1 }).update('args', List(), l => l.push([Map(ea), Map(eb)]));
expect(e1).to.equal(e2); // fail
expect(e1.get('args')).to.equal(List().push([Map(ea), Map(eb)])); // fail
});
});
我使用了以下內容:
- 節點:v6.3.1和V4.4.0(獨立工作站)
- 摩卡:V3.0.2
- 柴:V3.5.0
- 柴不變:V1.6.0
- 不變:v3.8.1
- 巴貝爾核心:v6.13.2
- 巴貝爾預設-ES2015:6.13.2
我的其他測試到目前爲止逝去的罰款,只有當我使用Map.update()
做我結束了這個問題。我在教程中還沒有看到使用這種方法的任何地方,但是,它看起來很基本,我希望它能夠工作。
你應該慶祝自己的答案,解決你的問題:) – astorije