首页 > 代码库 > angularjs之browserTrigger
angularjs之browserTrigger
今天推荐一款来自angularjs源码的单元测试辅助库browserTrigger,这是来自于ngScenario的一段代码。主要用户触发浏览器型行为更新ng中scope view model的值。
这是angularjs源码中单元测试的使用browserTrigger的实例:
it(‘should set the model to empty string when empty option is selected‘, function() { scope.robot = ‘x‘; compile(‘<select ng-model="robot">‘ + ‘<option value="">--select--</option>‘ + ‘<option value="http://www.mamicode.com/x">robot x</option>‘ + ‘<option value="http://www.mamicode.com/y">robot y</option>‘ + ‘</select>‘); expect(element).toEqualSelect(‘‘, [‘x‘], ‘y‘); browserTrigger(element.find(‘option‘).eq(0)); expect(element).toEqualSelect([‘‘], ‘x‘, ‘y‘); expect(scope.robot).toBe(‘‘); });
在这段代码中给browserTrigger传入你希望选择的select option,则它会帮助你tigger change,选中当前option,更触发更新ng select的viewmodel。
在browserTrigger中还为我们做了很多其他输入框或者html控件的触发接口,同时也加入了浏览器的兼容性。使得我们的测试更加方便不用考虑浏览器兼容性或者不同的html控件trigger不同的事件去更新scope的值。
具体更多信息请参考ng的官方测试和browserTrigger源码。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。