Questions tagged «angular2-testing»

2
angular2测试:由于它不是'input'的已知属性,因此无法绑定到'ngModel'
我正在尝试测试angular2双向绑定的控件input。这是错误: Can't bind to 'ngModel' since it isn't a known property of 'input'. app.component.html <input id="name" type="text" [(ngModel)]="name" /> <div id="divName">{{name}}</div> app.component.ts @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent implements OnInit { name: string; } app.component.spec.ts import { TestBed, async } from '@angular/core/testing'; import { AppComponent } from …

8
如何对依赖ActivatedRoute的参数的组件进行单元测试?
我正在对用于编辑对象的组件进行单元测试。该对象具有唯一性id,该唯一性用于从服务中托管的对象数组中获取特定对象。具体id是通过经由路由传递的参数采购,特别是通过ActivatedRoute类。 构造函数如下: constructor(private _router:Router, private _curRoute:ActivatedRoute, private _session:Session) { } ngOnInit() { this._curRoute.params.subscribe(params => { this.userId = params['id']; this.userObj = this._session.allUsers.filter(user => user.id.toString() === this.userId.toString())[0]; 我想在此组件上运行基本的单元测试。但是,我不确定如何注入id参数,并且组件需要此参数。 顺便说一句:我已经对该Session服务进行了模拟,因此不用担心。

2
Angular 2测试-异步函数调用-何时使用
在Angular 2中进行测试时,何时在TestBed中使用异步功能? 什么时候使用这个? beforeEach(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); }); 你什么时候使用这个? beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); })); 有人可以启发我吗?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.