与柴和Eshint的单元测试没有通过

时间:2014-12-17 19:37:50

标签: node.js unit-testing jshint

希望你能提供帮助,最近从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时,所有测试都通过了,所以我需要一些方法来清理这些测试。

Ĵ

1 个答案:

答案 0 :(得分:0)

测试undefined很棘手。有一些替代方法可以做到这一点。我通常会检查typeof(variable) === 'undefined

示例:

expect(typeof(ctrl.screens)).to.not.equal('undefined');
相关问题