【问题标题】:How can i synchronous test with supertest我如何与超测同步测试
【发布时间】:2015-06-05 08:20:10
【问题描述】:

代码:

should = require('should')
request = require('supertest')
request = request("stackoverflow.com");

describe "temp", ->

    input_output = [
        { input:"[mocha] [supertest]", output: ["asdf", "asdf"] }
        { input:"아버지가방에들어가신다", output: [ '아버지가방에들어가신다', '아버지', '가방', '에들', '어가', '신다' ] }
        { input:"hi hello", output: ["hi", "hello"] }
    ]

    for item in input_output 

        it "curl https://stackoverflow.com/search?q=#{item.input}", (done) ->

            request
                .get("/search?q=#{item.input}")
                .expect(200)
                .expect (res) ->
                    console.log item.input
                    return
                .end(done)

输出:

我预计以下输出:

我知道如果我在没有回调的情况下进行测试,那么我可以同步测试。但没用。

【问题讨论】:

    标签: coffeescript mocha.js supertest


    【解决方案1】:

    尝试在测试中使用局部范围的变量。像这样的:

    describe "temp", ->
    
        input_output = [
            { input:"[mocha] [supertest]", output: ["asdf", "asdf"] }
            { input:"아버지가방에들어가신다", output: [ '아버지가방에들어가신다', '아버지', '가방', '에들', '어가', '신다' ] }
            { input:"hi hello", output: ["hi", "hello"] }
        ]
    
        for item in input_output 
    
            it "curl http://stackoverflow.com/search?q=#{item.input}", (done) ->
                itemInput = item.input // <-- save in local scope var
    
                request
                    .get("/search?q=#{item.input}")
                    .expect(200)
                    .expect (res) ->
                        console.log itemInput // <-- use local scope var
                        return
                    .end(done)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-26
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多