javascript - How to check if "should has text" in Jasmine? - Stack Overflow

I need to do something like:expect(theElement.hasText()).toBe(true);Do you know how can I do it?I know

I need to do something like:

expect(theElement.hasText()).toBe(true);

Do you know how can I do it?

I know that there is a "getText" function in protractor, but, how can I use it? Should I do?:

expect(theElement.getText().lenght > 0).toBe(true);

Thanks!

I need to do something like:

expect(theElement.hasText()).toBe(true);

Do you know how can I do it?

I know that there is a "getText" function in protractor, but, how can I use it? Should I do?:

expect(theElement.getText().lenght > 0).toBe(true);

Thanks!

Share Improve this question edited May 26, 2015 at 13:15 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Apr 6, 2015 at 18:43 Broda NoelBroda Noel 2,0361 gold badge25 silver badges39 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

I find jasmine-matchers library very helpful in terms of additional useful matchers. toBeNonEmptyString() is a perfect fit here (also notice how readable it is):

expect(theElement.getText()).toBeNonEmptyString();

FYI, here is the underlying implementation:

matchers.toBeNonEmptyString = function() {
  return matchers.toBeString.call(this) &&
    this.actual.length > 0;
};

It is quite reliable: it checks the type and the length.

If you want to check length and don't want to use toBeNonEmpty, then check it in the callback

element(by.id('element_id')).getText().then(function (data) {
  expect(data.length).toBeGreaterThan(0);
});

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信