After the upgrade, Mocha can't even run a simple test. Here is his code:

const assert = require('assert'); it('should complete this test', function (done) { return new Promise(function (resolve) { assert.ok(true); resolve(); }) .then(done); }); 

I took this code from https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#boom-breaking-changes

I realized that he now throws an exception:

Error: Resolution method is overspecified. Specify a callback or return a Promise; not both.

But how to make it work, I did not understand. I use:

 node -v 6.9.4 mocha -v 3.2.0 

How to run this code now in a new and correct format?

  • It also says that this code should throw an error. What exactly do you want? - Mikhail Vaysman

1 answer 1

You are trying to use both the done function in the test script and return the Promise . So you can not do, you need to choose one thing (what actually says in the error message).

You have only two options for modifying the test script:

  1. Throw away done - function:

     it('should complete this test', function () { return new Promise(function (resolve) { assert.ok(true); resolve(); }); }); 
  2. Discard Promise :

     it('should complete this test', function (done) { setTimeout(function () { assert.ok(true); done(); }, 2); }); 

Which option to choose - decide for yourself.