Can we run a dynamical loop test in mocha when we obtain the dynamic array from one of the test cases something like below?
describe('test', () {
var array = [];
it('test 1', function(done) {
// get the array
// assume JSON = [ {number : 1, value : 1}, {number : 2, value : 2}]
}
// run loop test base on the array from test 1
array.forEach() {
it(`test {array.number}`, function(done) {
// sample
expect(array.number).to.be.equal(array.value)
}
}
it('test 3', function(done) {
// another test
}
}
So far, it seems to work fine if I ran in a separate js file instead of just one js file by passing the result of the JSON array (callback) to another test js file. What if I want it in one js file?
Reference: https://mochajs.org/#dynamically-generating-tests