Node.js 循环摩卡咖啡测试?

Node.js 循环摩卡咖啡测试?,node.js,mocha.js,Node.js,Mocha.js,我正在尝试循环一个mocha测试套件(我想根据无数的值测试我的系统,并获得预期的结果),但我无法让它工作。例如: 规格/示例\u规格咖啡: test_values = ["one", "two", "three"] for value in test_values describe "TestSuite", -> it "does some test", -> console.log value true.should.be.ok 问题是我的控

我正在尝试循环一个mocha测试套件(我想根据无数的值测试我的系统,并获得预期的结果),但我无法让它工作。例如:

规格/示例\u规格咖啡

test_values = ["one", "two", "three"]

for value in test_values
  describe "TestSuite", ->
    it "does some test", ->
      console.log value
      true.should.be.ok
问题是我的控制台日志输出如下所示:

three
three
three
one
two
three
我希望它看起来像这样:

three
three
three
one
two
three

如何在摩卡测试中循环这些值?

这里的问题是您正在关闭“value”变量,因此它将始终计算为其最后的值

类似这样的方法会奏效:

test_values = ["one", "two", "three"]
for value in test_values
  do (value) ->
    describe "TestSuite", ->
      it "does some test", ->
        console.log value
        true.should.be.ok
这是因为当值传递到此匿名函数时,它会复制到外部函数中的新值参数,因此不会被循环更改


编辑:添加了coffeescript“do”niceness。

您可以使用“数据驱动”


是的,我刚发现自己是洛杉矶人。谢谢