5

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?

limp_chimp
  • 13,475
  • 17
  • 66
  • 105

2 Answers2

10

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.

Louis
  • 146,715
  • 28
  • 274
  • 320
  • doesn't work for me, I have like a 20 second wait for a query call and it still jumps right to my assert before it can return. – PositiveGuy Oct 19 '15 at 06:25
  • @WeDoTDD If it does not work for you that's because there's *another problem with your code*. You should ask another question. Downvoting an answer that actually *does* work amounts to doing harm to Stack Overflow. – Louis Oct 19 '15 at 10:17
0

You can specify the timeout when running your test framework. For instance for mocha it would be like mocha -t 7000 . Alternatively, you can add a test with setTimeout just to create a delay (if the required delay is in between tests).

ttfreeman
  • 5,076
  • 4
  • 26
  • 33