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)
我知道如果我测试没有回调,那么我可以同步测试。但没有工作。
答案 0 :(得分:0)
尝试在测试中使用本地范围的变量。像这样:
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)