2014-12-21 73 views
1

我写了一个非常基本的测试,测试应该会成功,但古怪的事实并非如此。摩卡测试失败,但它不应该

it('should add the card to the tapis', function(){ 
     tapis.insererTapis(new Card("O", 5)); 
     tapis.insererTapis(new Card("E", 3)); 
     tapis.tapis.should.equal([{ 
      suit: "E", 
      val: 3 
     },{ 
      suit: "O", 
      val: 5 
     }]); 
     done(); 
    }); 

我在控制台这个奇怪的错误运行mocha test.js

0 passing (8ms) 
    1 failing 

    1) tapis should add the card to the tapis: 

     AssertionError: expected [ { suit: 'E', val: 3 }, { suit: 'O', val: 5 } ] to be [ { suit: 'E', val: 3 }, { suit: 'O', val: 5 } ] 
     + expected - actual 

`

后,大约should.js模块的问题吗?

+0

也侧面说明你并不需要'做()'同步测试,因为这和异步测试,你确实需要它,你都必须声明它作为测试功能的函数参数,并调用它完成时。 –

+0

是的,我知道的是,我刚刚加入'done',看看这个错误有事情做与同步/异步。 – hamou92

回答

0

你想要.should.eql测试深层等价,而.equal做了基本的===参考身份检查。

+0

我不知道'deeoEqual'存在。我没有在文档中看到它。我得到的错误'类型错误:对象#有没有方法“deepEqual” ' – hamou92

+0

哎呀,纠正。与柴的应该模块混淆should.js。 –

+0

没有用'.eql'工作过。我必须告诉你,几天前相同的测试代码正在工作。我不确定我是否更新了模块。 – hamou92

相关问题