I have an array of objects called allFeeds. Each object has a "name" key, which has an associated value called "url". I am trying to write a test in Jasmine that loops through the array and tests each object to ensures no "url" value is "undefined". My code is below. I have tried a couple iterations of the syntax/logic to no avail.
it('each object in allFeeds array should have a URL value associated with each key', function() {
allFeeds.forEach(function (arrayItem) {
var x = arrayItem.url
return x;
});
expect(x).not.toBeUndefined();
});
I have an array of objects called allFeeds. Each object has a "name" key, which has an associated value called "url". I am trying to write a test in Jasmine that loops through the array and tests each object to ensures no "url" value is "undefined". My code is below. I have tried a couple iterations of the syntax/logic to no avail.
it('each object in allFeeds array should have a URL value associated with each key', function() {
allFeeds.forEach(function (arrayItem) {
var x = arrayItem.url
return x;
});
expect(x).not.toBeUndefined();
});
Share
Improve this question
asked Apr 10, 2018 at 16:39
sjannettesjannette
751 gold badge3 silver badges14 bronze badges
0
1 Answer
Reset to default 4Looks like you place your 'check' at the wrong position.
it('each object in allFeeds array should have a URL value associated with each key', function() {
allFeeds.forEach(function (arrayItem) {
var x = arrayItem.url
// Check 'x' here
expect(x).not.toBeUndefined();
});
// Worng position - 'x' exists only in the loop
// expect(x).not.toBeUndefined();
});