Unit tests with chai and Eshint fail

Hope you can help, recently switched from jshint to eslint and Im just to see how to pass the tests to avoid making changes;

Take the following test for example

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

      

eshint complains about the following survey:

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 tests pass when I remove eshint from the task list, so I need to clean up those tests somehow.

J

+3


source to share


1 answer


Testing for undefined is tricky. There are several alternative ways to do this. I usually check typeof(variable) === 'undefined

.

Example:



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

      

0


source







All Articles