加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular中的量角器测试:如何在没有ng-bind和ng-mo

发布时间:2020-12-17 17:15:41 所属栏目:安全 来源:网络整理
导读:如何在没有ng-bind和ng-model的情况下检查范围内的变量? span ng-if="user.code === 'YELLOW'" span class="glyphicons glyphicons-circle-remove text-danger"/span Yellow/spanspan ng-if="user.code === 'GREEN'" span class="glyphicons glyphicons-cir
如何在没有ng-bind和ng-model的情况下检查范围内的变量?

<span ng-if="user.code === 'YELLOW'">
    <span class="glyphicons glyphicons-circle-remove text-danger"></span> Yellow
</span>
<span ng-if="user.code === 'GREEN'">
    <span class="glyphicons glyphicons-circle-exclamation-mark text-warning"></span> Green
</span>

我想用量角器检查user.code

使用ng-bind和ng-model它不起作用

browser.expect(element(by.binding('user.code')).getText()).to.eventually.equal('');

要么

browser.expect(element(by.model('user.code')).getAttribute('value')).to.eventually.equal('');

错误:

NoSuchElementError: No element found using locator: by.binding("user.code")
NoSuchElementError: No element found using locator: by.model("user.code")

解决方法

你不应该在量角器中测试那种东西.您应该从用户的角度编写测试.

但是,如果要测试使用评估.获取对DOM元素的引用,然后调用evaluate:

// Choose a DOM element bound to a scope that contains the value you
// want to test
expect($('span').evaluate('user.code')).toBe('some value');

http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.evaluate

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读