coffeescript - 我怎样才能与 super 测试同步测试

标签 coffeescript mocha.js supertest

代码:

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)

输出:

我预计输出如下:

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

最佳答案

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

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)

关于coffeescript - 我怎样才能与 super 测试同步测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24644293/

相关文章:

backbone.js - 如何使用 2 种不同的模型扩展 Backbone 模型

javascript - 在 Coffeescript 中编写递归 setTimeout 循环

reactjs - 引用错误 : before is not defined (mocha/protractor)

javascript - Mocha/Sinon - ES6 Promise 内使用 child_process.exec 进行单元测试/ stub 功能

javascript - 未处理的 Promise 拒绝警告 : TypeError: First argument must be a string or Buffer

node.js - 如何用 super 测试检查不存在的头字段?

javascript - 将 Javascript 转换为 Coffeescript

javascript - Gulp-coffee 删除不存在的文件

oauth - 如何使用Mocha在sails js中对google oauth护照进行单元测试

node.js - 如何使用 supertest 和 mocha 测试快速渲染