代码:
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)
输出:
- 温度
- 你好你好
- ✓ curl https://stackoverflow.com/search?q=[mocha] [ super 测试](1017 毫秒)
- 你好你好
- ✓ curl https://stackoverflow.com/search?q=아버지가방에들어가신다 (1023 毫秒)
- 你好你好
- ✓ curl https://stackoverflow.com/search?q=hi你好(1124 毫秒)
- 你好你好
我预计输出如下:
- 温度
- [ Mocha ] [超测]
- ✓ curl https://stackoverflow.com/search?q=[mocha] [ super 测试](1017 毫秒)
- 한버지가방에들어가신다
- ✓ curl https://stackoverflow.com/search?q=아버지가방에들어가신다 (1023 毫秒)
- 你好你好
- ✓ curl https://stackoverflow.com/search?q=hi你好(1124 毫秒)
- [ Mocha ] [超测]
我知道如果我在没有回调的情况下进行测试,那么我可以进行同步测试。但没有用。
最佳答案
尝试在测试中使用局部范围的变量。像这样:
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/