Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No unused expressions in mocha chai unit test using standardJS

Tags:

javascript

I am using standardJS for testing my code. Also I am using mocha chai. With that I'm getting the error expect an assignment or function call and instead saw an expression. for this line:

expect(err).to.be.null

But this line is correct, so what am I doing wrong?

like image 478
user3142695 Avatar asked Jul 13 '17 11:07

user3142695


1 Answers

Here are two possible solutions:

1. Use dirty-chai

Using dirty-chai you can change this:

expect(err).to.be.null

to this:

expect(err).to.be.null()

Use it like this:

var chai = require('chai');
var dirtyChai = require('dirty-chai');
var expect = chai.expect

chai.use(dirtyChai);

expect(err).to.be.null()

2. Disable the rule by adding a comment to the top of each test file

/* eslint-disable no-unused-expressions */

Note: Please read this comment for more information.

like image 88
Kayvan Mazaheri Avatar answered Oct 02 '22 00:10

Kayvan Mazaheri