2017-07-17 63 views
0

我第一次得到ul元素的總數是這樣的。如果量角器中的條件工作不正常(AngularJS)

var dropElementLength = dropdown_ul.all(by.tagName('li')).count(); 

現在dropElementLength有4.如果測試這個變量,如果條件如此。

if(dropElementLength == 4) { 
    expect(dropElementLength).toEqual(34); 
} else { 
    expect(dropElementLength).toEqual(634); 
} 

錯誤是'期望4到等於634',其中錯誤應該'預計4到34'。但是,如果條件應爲true,因爲dropElementLength等於4.

爲什麼如果條件不成立?

+0

在開發人員工具中調試您的代碼。並且如果條件放置斷點。 –

回答

1

dropElementLength返回承諾不是布爾。

使用柴AS-承諾: expect(dropdown_ul.all(by.tagName('li')).count()).to.eventually.equals(34);

0

@Kacper評論後,我寫這段代碼解決了我的問題。

dropElementLength.then(function (value) { 
    if (value === 4) { 
      expect(value).toEqual(34); 
    } else { 
      expect(value).toEqual(634); 
    } 
})