量角器 - 检查字符串的最佳方法在e2e测试中不是空的

时间:2016-02-24 15:16:38

标签: javascript testing jasmine protractor gulp-protractor

使用e2e测试确保找到值(例如不是空字符串)的最佳方法是什么,我的示例只是匹配文本本身,我想计算字符串长度&确保它不是0.

describe 'Device Details', ->
device = ionic.Platform.device()
details =
'deviceManufacturer': $('#deviceManufacturer'),
'deviceModel': $('#deviceModel')

it 'Device Manufacturer must not be empty', ->
  expect(details.deviceModel.getText()).toEqual '10'

3 个答案:

答案 0 :(得分:14)

有不同的方法可以做到这一点,但我更喜欢toBeNonEmptyString()中的jasmine-matchers package - 简单易读:

expect(details.deviceModel.getText()).toBeNonEmptyString();

答案 1 :(得分:10)

不使用茉莉花匹配器。

   details.deviceModel.getText().then(function(text) {
      expect(text.length).not.toEqual(0)
    });

请参阅以下评论以获取警告

答案 2 :(得分:7)

尽量不要。('')检查不是空的

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

===其他情况====

expect(details.deviceModel.getText()).not.toBe('');