How do I test ‘normal’ (non-Node specific) JavaScript functions with Mocha?

Thanks to the other answers here, I’ve got things working. One thing which wasn’t mentioned though—perhaps because it’s common knowledge among Noders—was that you need to assign the result of the require call to a variable, so that you can refer to it when calling your exported functions from within the test suite. Here’s my … Read more

Reset “called” Count on Sinon Spy

This question was asked a while back but may still be interesting, especially for people who are new to sinon. this.spied.reset() is not needed as Obj.prototype.spiedMethod.restore(); removes the spy. Update 2018-03-22: As pointed out in some of the comments below my answer, stub.reset will do two things: Remove the stub behaviour Remove the stub history … Read more

Running Mocha + Istanbul + Babel

Using Babel 6.x, let’s say we have file test/pad.spec.js: import pad from ‘../src/assets/js/helpers/pad’; import assert from ‘assert’; describe(‘pad’, () => { it(‘should pad a string’, () => { assert.equal(pad(‘foo’, 4), ‘0foo’); }); }); Install a bunch of crap: $ npm install babel-istanbul babel-cli babel-preset-es2015 mocha Create a .babelrc: { “presets”: [“es2015”] } Run the tests: … Read more

How to set timeout on before hook in mocha?

You need to set a timeout in your describe block rather than in the hook if you want it to affect all the tests in the describe. However, you need to use a “regular” function as the callback to describe rather than an arrow function: describe(‘test’, function () { this.timeout(10000); before(…); it(…); }); In all … Read more

Why am I getting “Error: Resolution method is overspecified”?

Just drop .then(done); and replace function(done) with function() You are returning a Promise so calling done is redundant as it said in error message In the elder versions you had to use callback in case of async methods like that it (‘returns async’, function(done) { callAsync() .then(function(result) { assert.ok(result); done(); }); }) Now you have … Read more

How to Unit Test React-Redux Connected Components?

A prettier way to do this, is to export both your plain component, and the component wrapped in connect. The named export would be the component, the default is the wrapped component: export class Sample extends Component { render() { let { verification } = this.props; return ( <h3>This is my awesome component.</h3> ); } … Read more

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