Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Immutablejs Map.update中断单元测试_Node.js_Mocha.js_Chai_Immutable.js_Chai Immutable - Fatal编程技术网

Node.js Immutablejs Map.update中断单元测试

Node.js Immutablejs Map.update中断单元测试,node.js,mocha.js,chai,immutable.js,chai-immutable,Node.js,Mocha.js,Chai,Immutable.js,Chai Immutable,我正在学习Redux,下面的教程使用ImmutableJs。我对ImmutableJs完全陌生,我只是通过API文档开始学习。我的练习应用程序比教程复杂得多,所以我有点偏离了方向,可能迷路了 每当我使用Map.update()方法时,我都无法找到成功测试代码的方法。下面是我写的一个测试,试图找出问题所在: import chai, {expect} from 'chai'; import chaiImmutable from 'chai-immutable'; import {List, Map

我正在学习Redux,下面的教程使用ImmutableJs。我对ImmutableJs完全陌生,我只是通过API文档开始学习。我的练习应用程序比教程复杂得多,所以我有点偏离了方向,可能迷路了

每当我使用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
  • chai不可变:v1.6.0
  • 不可变:v3.8.1
  • 巴别塔核心:v6.13.2
  • 巴别塔-preset-es2015:6.13.2

到目前为止,我的其他测试都通过得很好,只有当我使用
Map.update()
时,我才会出现这个问题。我在教程中还没有看到使用此方法的任何地方,但是,它似乎非常基本,我希望它能起作用。

在GitHub上深入挖掘了一些不可变问题后,发现我在使用
List.push()
时遇到的问题是可变结构和不可变结构的混合。更改:

const e1 = Map({ test: 1 }).update('args', List(), l => l.push([Map(ea), Map(eb)]));


而且一切都很好

你应该将自己的答案标记为解决问题:)
const e1 = Map({ test: 1 }).update('args', List(), l => l.push(List([Map(ea), Map(eb)])));