node.js - Loop Mocha tests? -


i'm trying loop mocha test suite (i want test system against myriad of values expected results), can't work. example:

spec/example_spec.coffee:

test_values = ["one", "two", "three"] value in test_values describe "testsuite", -> "does test", -> console.log value true.should.be.ok 

the problem console log output looks this:

three 3 three 

where want this:

one 2 3 

how can loop on these values mocha tests?

the issue here you're closing on "value" variable, , evaluate whatever last value is.

something work:

test_values = ["one", "two", "three"] value in test_values (value) -> describe "testsuite", -> "does test", -> console.log value true.should.be.ok 

this works because when value passed anonymous function, copied new value parameter in outer function, , therefore not changed loop.

edit: added coffeescript "do" niceness.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -