I have one forEach that does a bunch of tests. If a test passes I store a value in array. I then want to execute a second forEach based on that array. So if all tests fail, second forEach doesn't run at all, if one or more passes, it runs tests for each value in the array. However, the forEach always takes the initial value, its always seen as empty regardless of test results. Is it possible to delay creating the second forEach until the first is finished? So it will get the actual value of the dynamic array? Or is this not possible?
Here is the structure (some non-important stuff omitted):
let amount;
const sent = [];
constants.assets.forEach((asset) => {
describe(`Send ${asset}`, function() {
const suite = this.title;
let driver = null;
// Test Hooks
before(async function() {
// runs before all test cases
this.timeout(installTimeout);
log.out('Creating driver');
try {
log.out('Start Testing');
} catch (error) {
log.out('Error at before hook ' + suite + ': ' + error);
assert.fail(error);
}
});
after(async function() {
// runs after all tests cases
this.timeout(installTimeout);
log.out('Destroying driver');
try {
await mobileDriver.destroyDriver(global.test.driver);
log.out('End Testing');
} catch (error) {
log.out('Error at after hook ' + suite + ': ' + error);
assert.fail(error);
}
});
beforeEach(async function() {
// runs before each test case
await log.initialize(suite, this.currentTest.title);
log.out("Start Test: " + suite + "/" + this.currentTest.title);
});
afterEach(async function() {
// runs after each test case
log.out("End Test: " + suite + "/" + this.currentTest.title);
});
// Test Cases
it(test.name('Login'), async function () {
this.timeout(standardTimeout);
});
it(test.name(`Send ${asset}`), async function () {
this.timeout(standardTimeout);
sent.push(asset)
});
});
});
sent.forEach(function (asset) {
if (sent.includes(asset)) {
describe(`Send ${asset} Transaction Verification`, function() {
const suite = this.title;
let driver = null;
// Test Hooks
before(async function() {
// runs before all test cases
this.timeout(installTimeout);
log.out('Creating driver');
try {
log.out('Start Testing');
} catch (error) {
log.out('Error at before hook ' + suite + ': ' + error);
assert.fail(error);
}
});
after(async function() {
// runs after all tests cases
this.timeout(installTimeout);
log.out('Destroying driver');
try {
await mobileDriver.destroyDriver(global.test.driver);
log.out('End Testing');
} catch (error) {
log.out('Error at after hook ' + suite + ': ' + error);
assert.fail(error);
}
});
beforeEach(async function() {
// runs before each test case
await log.initialize(suite, this.currentTest.title);
log.out("Start Test: " + suite + "/" + this.currentTest.title);
});
afterEach(async function() {
// runs after each test case
log.out("End Test: " + suite + "/" + this.currentTest.title);
});
// Test Cases
it(test.name('Login'), async function () {
this.timeout(standardTimeout);
});
}
});
});