5

I am testing multiple responses but always end up with the same error message:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/this/file/path.js)
   let invalid = 'something_invalid';

    it('With valid appid', (done) => {
        request(server).get(`/game/info/${valid}`)
            .then((err, res) => {

                let json = res.body;

                expect(200);
                expect(json.name).to.equal("Rust");
                done();
            }).catch(err => console.log(err))
    });

Where the response is:

{
    "name": "Rust",
    "appid": 252490,
    "description": "The only aim in Rust is to survive - Overcome struggles such as hunger, thirst and cold. Build a fire. Build a shelter. Kill animals. Protect yourself from other players.",
    "publishers": [
        "Facepunch Studios"
    ],
    "price_text": "€33.99",
    "platforms": {
        "windows": true,
        "mac": true,
        "linux": false
    },
    "likes": 374668
}

I've looked everywhere but the solution to the problem never solved it. Any idea on what I am doing wrong?

get_php_workin
  • 438
  • 7
  • 14

2 Answers2

6

Try to set a longer timeout when running your test:

mocha --timeout 10000

Or in each suite or each test manually:

describe('...', function(){
  this.timeout(10000);

  it('...', function(done){
    this.timeout(10000);
    setTimeout(done, 10000);
  });
});
koko-js478
  • 1,703
  • 7
  • 17
2

This will not wait for 10secs, if response came in 7secs it exits the test case, please try this

    it('With valid appid', (done) => {
        request(server).get(`/game/info/${valid}`)
            .then((err, res) => {

                let json = res.body;

                expect(200);
                expect(json.name).to.equal("Rust");
                done();
            }).catch(err => console.log(err))
    }, 10000);

muthu
  • 723
  • 10
  • 27