javascript - 比较数组时出现 Chai 断言错误
问题描述
在使用 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 作为我的测试运行器。
解决方案
推荐阅读
- python - 如何在 Airflow Dag 脚本中捕获从 Python 类返回的值?
- .net - 使用 Amazon S3 客户端配置重试策略
- javascript - 在无效时更改输入背景颜色
- bash - 使用 Bash 将字符串转换为 Git 分支名称格式
- java - 将巨大的 CSV 文件内容转换为可快速查询的数据存储的最佳方法?
- reactjs - 每次点击页面时 React Typescript Mutation 调用 api
- wordpress - 我的网站的实时版本和 hpanel 出现不同
- javascript - 如何在不影响 DOM 的情况下使框展开并从原点过渡到屏幕中心?
- javascript - 如何在三元运算符条件下附加字符串和 html 标签?
- flutter - Flutter 导致不同屏幕的用户角色(firebase)