Search code examples
node.jsmocha.jssupertest

Setting timeouts with supertest not working


I'm trying to test my server with some code like so:

describe 'POST /do/some/stuff/', ->
  it 'should do this thing', (done) ->
    request app
      .post '/do/some/stuff/'
      .timeout 10000
      .expect 200
      .end (err, res) ->
        return done err if err?
        done()

The thing that the server is doing usually takes a few seconds, which is longer than the default timeout of 2000ms, so I call .timeout 10000. However, despite this, when I run the code I get:

1) POST /do/some/stuff/ should do this thing:
   Error: timeout of 2000ms exceeded

What do I need to do to increase this timeout?


Solution

  • Changing the timeout on your request object does not change anything to Mocha's default timeout. Doing this.timeout(10000) (whatever the CoffeeScript equivalent is) inside your test should take care of that.