简体   繁体   English

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

[英]Unit tests with chai and Eshint are not passing

Hope you can help, recently moved from jshint to eslint and Im looking to see how to get my tests to pass wihtout making changes; 希望你能帮忙,最近从jshint转到eslint,我正在寻找如何让我的测试通过而不做出改变;

Take for exmaple the following test 以下测试为例

expect(ctrl.screens).to.not.be.undefined;

eshint complains with the following expection; eshint抱怨以下期望;

error  Expected an assignment or function call and instead saw an expression  no-unused-expressions

Changing the test to; 将测试更改为;

expect(ctrl.screens).to.not.be.undefined();

Gives the following error: 给出以下错误:

TypeError: '[object Object]' is not a function (evaluating 'expect(ctrl.screens).to.not.be.undefined()')

Any ideas what approach to take here? 有什么想法在这里采取什么方法? All the tests pass when I remove eshint from the task list so I need for some way to clean up these tests. 当我从任务列表中删除eshint时,所有测试都通过,所以我需要一些方法来清理这些测试。

J Ĵ

Testing for undefined is tricky. 测试undefined很棘手。 There are some alternative ways to do it. 有一些替代方法可以做到这一点。 I normally check for typeof(variable) === 'undefined . 我通常检查typeof(variable) === 'undefined

Example: 例:

expect(typeof(ctrl.screens)).to.not.equal('undefined');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM