Javascript 比较数组时出现错误

Javascript 比较数组时出现错误,javascript,unit-testing,phantomjs,karma-runner,chai,Javascript,Unit Testing,Phantomjs,Karma Runner,Chai,在使用Chai时,我在试图断言结果应该等于数组时遇到了一个奇怪的错误 代码示例 describe("compare array", function() { it("should return an empty array", function() { const result = getEmptyList(); // just a silly example expect(result).to.equal([]);

在使用Chai时,我在试图断言结果应该等于数组时遇到了一个奇怪的错误

代码示例

   describe("compare array", function() {
        it("should return an empty array", function() {
            const result = getEmptyList(); // just a silly example
            expect(result).to.equal([]);
        });
   });
结果

  × compare array
    PhantomJS 2.1.1 (Windows 8.0.0)
  expected [ find: [Function] ] to equal [ find: [Function] ]
  AssertionError@C:/Code/example/node_modules/chai/chai.js:9449:24
  assert@C:/Code/example/node_modules/chai/chai.js:239:31
  assertEqual@C:/Code/example/node_modules/chai/chai.js:1387:18
  methodWrapper@C:/Code/example/node_modules/chai/chai.js:7824:30
  test/unit/utils/example.js:5:32
当我期望结果的长度等于零时,它工作得很好。任何人都可以分享一些关于为什么会发生这种情况的见解。为什么突然期望
[find:[Function]]
而不是期望的
[]


我正在使用Karma作为我的测试运行程序。

因为一个数组永远不会与另一个数组进行
==
,对于数组,您需要以下限定符:

从文档中:

使链中跟随的所有
.equal
include
.members
.keys
.property
断言使用深度相等,而不是严格的(
=
)相等


谢谢TJ,你让我开心@程序员-很高兴为您提供帮助!我后来才意识到它必须是一个复制品,并找到了它的标准。太好了,不用担心!
expect(result).to.deep.equal([]);
// --------------^^^^^