3

codes:

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)

outputs:

i expected below outputs:

i know if i test without callback then i can synchronous test. but didnt work.

Community
  • 1
  • 1

1 Answers1

0

Try using a locally scoped variable inside the test. Something like this:

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)
JME
  • 3,452
  • 12
  • 22