Reputation: 703
Hi I just want to ask if there is a way that you can call loops inside module.exports?
module.exports = {
'GZAIS Create New Asset': function (test) {
test
.assert.exists('input#asset_name', 'asset input exists')
.assert.exists('textarea#asset_description', 'asset description exists')
.assert.exists('input#asset_type', 'asset type exists')
.assert.exists('input#date_purchased', 'date purchased exists')
.assert.exists('.filter-option', 'status exists')
.assert.exists('input#serial_number', 'Serial Number exists')
.assert.exists('input#supplier', 'Supplier field exists')
.assert.exists('input#reason', 'Reason for purchase field exists')
.done();
}
};
right now this is my design on asserting the fields if fields are existing, what I want to do is use a for loop to avoid so much repetition.
so it would pretty much look like this
var assetInput = ['asset_name','asset_description','asset_type','date_purchased','serial_number','supplier','reason'];
module.exports = {
'GZAIS Create New Asset': function (test) {
test
for(var i=0; i<assetInput.length; i++){
.assert.exists('input#'+assetInput[i], assetInput[i] + 'exists')
}
.done();
}
};
but the problem is this code won't work, do you guys have any idea how can I implement loops inside module.exports?
Upvotes: 0
Views: 318
Reputation: 686
From what I see, this is just a simple syntax error.
You are missing a test
in front of
.assert.exists('input#'+assetInput[i], assetInput[i] + 'exists')
this must be turned into:
test.assert.exists('input#'+assetInput[i], assetInput[i] + 'exists')
Upvotes: 2