javascript - Jasmine - using forEach to test that keyvalue pairs in array of objects are defined - Stack Overflow

I have an array of objects called allFeeds.Each object has a "name" key, which has an assoc

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
Add a ment  | 

1 Answer 1

Reset to default 4

Looks 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();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744371191a4570960.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信