博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS + Unit Testing] Testing a component with requiring ngModel
阅读量:5052 次
发布时间:2019-06-12

本文共 1277 字,大约阅读时间需要 4 分钟。

The component test:

describe('The component test', () => {    let component, $componentController, $controller, $injector, $scope;    beforeEach(module("componennts.module"));    beforeEach(inject((_$componentController_, _$controller_, _$injector_, _$rootScope_) => {        $componentController = _$componentController_;        $controller = _$controller_;        $injector = _$injector_;        $scope = _$rootScope_.$new();    }));    describe('Controller', () => {        it('should have ng-model with the correct binding', () => {                let locals = {                $scope: $scope,                $element: angular.element('
'), $attrs: { ngModel: 'value' } }; locals.$scope.value = [1]; let ngModelController = $injector.get('ngModelDirective')[0].controller; let ngModelInstance = $controller(ngModelController, locals); $scope.$digest(); component = $componentController('myComponent', null, { ngModel: ngModelInstance }); component.$onInit(); expect(component).toBeDefined(); expect(component._selectedValues).toEqual([1]); // _selectedValues = ngModel.$viewValue }); });});

 

转载于:https://www.cnblogs.com/Answer1215/p/9958978.html

你可能感兴趣的文章
win7下64位系统memcache/memcached安装教程
查看>>
C#用DesignSurface实现一个简单的窗体设计器
查看>>
CUDA跟OpenCV的混合编程,注意OpenCV需要重新编译
查看>>
Team Foundation Server 2010 Performance Tuning – Lessons learned
查看>>
obj文件转换为gltf的方法
查看>>
系统运行与维护
查看>>
纯css画哆啦A梦
查看>>
SpringIOC学习一
查看>>
摄像头脸部识别 (1)opencv 抓取视频数据并保存
查看>>
[译]Django first steps Part3
查看>>
cat 参数
查看>>
SharePoint 2013 设置自定义布局页
查看>>
Node.js 初学者的入门资源汇总
查看>>
MetaQ
查看>>
【转】变量命名(简短且无歧义)
查看>>
转载:固定表格布局下的各浏览器对与表格宽度计算算法不同
查看>>
SQL Server 找出值得优化的语句
查看>>
mysql爱之深探测
查看>>
单点登录技术
查看>>
使用LINQ取得已选中的CheckBox .
查看>>