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

Protractor - what best way to check a string IS NOT empty in e2e testing

本文关键字:最佳 方法 字符串 检查 e2e 测试 量角器      更新时间:2023-09-26

使用 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'

try not.toBe('') 检查不为空

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

=== 其他情况 ====

 expect('hello world').not.toBe(''); //true 
 expect('').toBe(''); //true

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

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

不使用茉莉花匹配器。

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

有关注意事项,请参阅下面的评论