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

Invariant Violation: Could not find “store” in either the context or props of “Connect(SportsDatabase)”

It’s pretty simple. You’re trying to test the wrapper component generated by calling connect()(MyPlainComponent). That wrapper component expects to have access to a Redux store. Normally that store is available as context.store, because at the top of your component hierarchy you’d have a <Provider store={myStore} />. However, you’re rendering your connected component by itself, with … 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

How to programmatically skip a test in mocha?

You can skip tests by placing an x in front of the describe or it block, or placing a .skip after it. xit(‘should work’, function (done) {}); describe.skip(‘features’, function() {}); You can also run a single test by placing a .only on the test. for instance describe(‘feature 1’, function() {}); describe.only(‘feature 2’, function() {}); describe(‘feature … Read more

How to access and test an internal (non-exports) function in a node.js module?

The rewire module is definitely the answer. Here’s my code for accessing an unexported function and testing it using Mocha. application.js: function logMongoError(){ console.error(‘MongoDB Connection Error. Please make sure that MongoDB is running.’); } test.js: var rewire = require(‘rewire’); var chai = require(‘chai’); var should = chai.should(); var app = rewire(‘../application/application.js’); var logError = app.__get__(‘logMongoError’); … Read more

In mocha testing while calling asynchronous function how to avoid the timeout Error: timeout of 2000ms exceeded

You can either set the timeout when running your test: mocha –timeout 15000 Or you can set the timeout for each suite or each test programmatically: describe(‘…’, function(){ this.timeout(15000); it(‘…’, function(done){ this.timeout(15000); setTimeout(done, 15000); }); }); For more info see the docs.

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