希望您能提供帮助,最近从 jshint 转移到 eslint,我正在寻找如何在不进行更改的情况下让我的测试通过;
以下面的测试为例
expect(ctrl.screens).to.not.be.undefined;
eshint 提示以下期望;
error Expected an assignment or function call and instead saw an expression no-unused-expressions
将测试更改为;
expect(ctrl.screens).to.not.be.undefined();
出现以下错误:
TypeError: '[object Object]' is not a function (evaluating 'expect(ctrl.screens).to.not.be.undefined()')
任何想法在这里采取什么方法?当我从任务列表中删除 eshint 时,所有测试都通过了,所以我需要一些方法来清理这些测试。
J
最佳答案
测试 undefined 是棘手的。有一些替代方法可以做到这一点。我通常会检查 typeof(variable) === 'undefined
。
示例:
expect(typeof(ctrl.screens)).to.not.equal('undefined');
关于node.js - chai 和 Eshint 的单元测试没有通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27533471/