我正在尝试使用如下代码测试我的服务器:
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()
服务器正在做的事情通常需要几秒钟,比默认超时 2000 毫秒长,所以我调用 .timeout 10000
。然而,尽管如此,当我运行代码时,我得到:
1) POST /do/some/stuff/ should do this thing:
Error: timeout of 2000ms exceeded
我需要做什么来增加超时时间?
最佳答案
更改 request
对象的超时不会更改 Mocha 的默认超时。在你的测试中执行 this.timeout(10000)
(无论 CoffeeScript 等价物是什么)应该可以解决这个问题。
关于node.js - 使用 supertest 设置超时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23641071/