3

i'm trying to figure out why this test runs twice:

it ( "should verify file exists with a one name filename ", function ( done ){   
    var fileNameOneChar = "/Users/myusername/t.mp3"; 
    console.log(" the file path ", fileNameOneChar ); 
    expect( myApi.fileExists( fileNameOneChar ) ).to.be( true ); 
    done();
});

the test runs twice in a row, (although its only defined once) the first time it passes (which is okay, that file actually exists and the api is working fine), the second time it fails with an error : "Error: timeout of 5000ms exceeded" .

WHy does the test runs twice ? i have looked everywhere foe the time out error for a while now, havent found anything on Mocha.

elcomputerguy
  • 141
  • 1
  • 9

1 Answers1

4

The same was happening to me minutes ago and I found a workaround (not a fix): Run the tests in sync mode.

Basically you need to avoid setting up the done parameter of the it method

Below an example of how my test looks like now

describe('API /users Endpoint', function () {
  it('GET /users should return a JSON list of users', function (done) {
    request
      .get(config.api.prefix+'users')
      .set('bearer',config.api.key)
      .end(function(err,res){
        if (err) {
          return done(err);
        }
        res.statusCode.should.equal(200);
        res.body.should.not.be(null);
        res.body.posts.should.not.be(undefined);
        res.body.posts.should.not.have.length(0);
      });
  });

Hope it helps!

Franco Laiuppa
  • 111
  • 2
  • 4