Reputation: 432
I have a unit test to contol a list of elements.
ex :
arr = [
{ element : "aaa",
validation : false
},
{ element: "bbbb",
validation: true
},
{ element: "ccc",
validation: false
}
During my unit test , i want to list all invalid elements but with mocha and chai, he stop on the first invalid element. How to force mocha to make a test with error ?
My code "it" :
it('Read element', () => {
let length = arr.length - 1;
for (let i =0; i<= length; i++ ) {
assert.equal(arr[i].validation, true, 'route ' + arr[i].element+ ' should be valid);
}
});
Upvotes: 0
Views: 59
Reputation: 47182
You could use the deepEqual matcher instead of looping over your array and construct an array to match against.
let validationArray = arr = [
{ element : "aaa",
validation : true
},
{ element: "bbbb",
validation: true
},
{ element: "ccc",
validation: true
}];
assert.deepEqual(arr, validationArray);
Upvotes: 2
Reputation: 203359
You could create a separate test per array item:
describe('Read element', () => {
arr.forEach(item => {
it('route ' + item.element + ' should be valid', () => {
assert.equal(item.validation, true);
});
});
});
Upvotes: 3