如何在Jasmine测试中构造beforeEach函数

时间:2018-06-06 11:53:09

标签: javascript asynchronous testing jasmine

完整代码here

for (var i = 0; i < allFeeds.length; i++) {
    asyncLoad(i);
    let j = i + 1;
}

function asyncLoad(i) {
  describe('feed', function() {
    let priorFeed;
    let latterFeed;

     beforeEach(function(done) {
       loadFeed(i, function(){
         priorFeed = $('.header-title').text();
         loadFeed(j, function(){
           latterFeed = $('.header-title').text();
         });
       });
     });

     it('changes title and content on load', function() {
       expect(priorFeed).not.toBe(latterFeed);
     });
   });
 }

});

使用Jasmine测试,对于此测试,标题不应与之前的标题相同。但是要么是因为“在超时内没有调用异步回调”或者没有定义url而得到错误。 AsyncLoad参数是i,然后在loadFeed中使用,然后将loadFeed i与loadFeed i + 1进行比较,它们不应该相同,但这不起作用。

我还能如何构建以使j不会超过Feed的数量,或者检查此Feed与上次Feed相比?

0 个答案:

没有答案