Mocha not exiting after test

I know it is a bit late to answer this, but I was facing a similar problem and saw your post. In mocha 4.0.0, they changed the behavior of tests on finalization.From here: If the mocha process is still alive after your tests seem “done”, then your tests have scheduled something to happen (asynchronously) and … Read more

Nice way to get rid of no-unused-expressions linter error with chai

You can disable the rule for the entire file using eslint-disable at the top of the file in question: /* eslint-disable no-unused-expressions */ expect(someTrueValue).to.be.true; However, adding this at the top of every test file can be tedious. To disable this rule for all relevant files, you can: Put a new .eslintc configuration file in the … Read more

Chai: how to test for undefined with ‘should’ syntax

This is one of the disadvantages of the should syntax. It works by adding the should property to all objects, but if a return value or variable value is undefined, there isn’t a object to hold the property. The documentation gives some workarounds, for example: var should = require(‘chai’).should(); db.get(1234, function (err, doc) { should.not.exist(err); … Read more

Testing for errors thrown in Mocha [duplicate]

You’re not passing your function to assert.throws() the right way. The assert.throws() function expects a function as its first parameter. In your code, you are invoking iThrowError and passing its return value when calling assert.throws(). Basically, changing this: assert.throws(iThrowError(), Error, “Error thrown”); to this: assert.throws(iThrowError, Error, “Error thrown”); should solve your problem. With args: assert.throws(() … Read more

When should you use render and shallow in Enzyme / React tests?

As per the Enzyme docs: mount(<Component />) for Full DOM rendering is ideal for use cases where you have components that may interact with DOM apis, or may require the full lifecycle in order to fully test the component (ie, componentDidMount etc.) vs. shallow(<Component />) for Shallow rendering is useful to constrain yourself to testing … Read more

Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai

The issue is caused by this: .catch((error) => { assert.isNotOk(error,’Promise error’); done(); }); If the assertion fails, it will throw an error. This error will cause done() never to get called, because the code errored out before it. That’s what causes the timeout. The “Unhandled promise rejection” is also caused by the failed assertion, because … Read more

How do I properly test promises with mocha and chai?

The easiest thing to do would be to use the built in promises support Mocha has in recent versions: it(‘Should return the exchange rates for btc_ltc’, function() { // no done var pair=”btc_ltc”; // note the return return shapeshift.getRate(pair).then(function(data){ expect(data.pair).to.equal(pair); expect(data.rate).to.have.length(400); });// no catch, it’ll figure it out since the promise is rejected }); Or … Read more

What is the difference between “assert”, “expect”, and “should” in Chai?

The differences are documented there. The three interfaces present different styles of performing assertions. Ultimately, they perform the same task. Some users prefer one style over the other. This being said, there are also a couple technical considerations worth highlighting: The assert and expect interfaces do not modify Object.prototype, whereas should does. So they are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)