If I am running a unit test that is testing the logic based only on the length of a passed in array, should I be concerned about setting the length of it explicitly?
For example:
function foo(arrayFoo) {
return arrayFoo.length > 10 ? 'too long' : 'just right';
}
And for the test:
let testArray = [];
testArray.length = 11;
const expected = 'too long'
const actual = foo(testArray);
expect(actual).toBe(expected);
I understand that this is creating an array of undefineds
but is there a better way or am I just being paranoid?
Aucun commentaire:
Enregistrer un commentaire