angular2-testing

How to replace a component used in @viewChildren for a test double?

痞子三分冷 提交于 2021-02-08 13:10:17
问题 Suppose I have a component I want to test that uses a very complex component. Furthermore it calls some of its methods using references obtained by @viewChildren . For example @Component({ moduleId: module.id, selector: 'test', template: '<complex *ngFor='let v of vals'></complex>' , }) export class TestComponent{ vals = [1,2,3,4] @ViewChildren(ComplexComponent) cpxs : QueryList<ComplexComponent> // .... } How can I replace the complex-component for a test double in `TestBed'? Something like

How to replace a component used in @viewChildren for a test double?

穿精又带淫゛_ 提交于 2021-02-08 13:09:29
问题 Suppose I have a component I want to test that uses a very complex component. Furthermore it calls some of its methods using references obtained by @viewChildren . For example @Component({ moduleId: module.id, selector: 'test', template: '<complex *ngFor='let v of vals'></complex>' , }) export class TestComponent{ vals = [1,2,3,4] @ViewChildren(ComplexComponent) cpxs : QueryList<ComplexComponent> // .... } How can I replace the complex-component for a test double in `TestBed'? Something like

Angular2 how to Mock Activated Route Params subscribed

旧时模样 提交于 2020-06-12 16:16:48
问题 I have a components that gets a value from the params property of a ActivatedRoute. The components looks like: ...... constructor(public userRegistration: UserRegistrationService, public userLogin: UserLoginService, public router: Router, public route: ActivatedRoute) { } ngOnInit() { this.verificationCode = new FormControl('', [Validators.required]); this.confirmationCodeForm = new FormGroup({verificationCode: this.verificationCode}); //****************************** this.sub = this.route

Angular2 how to Mock Activated Route Params subscribed

烈酒焚心 提交于 2020-06-12 16:15:24
问题 I have a components that gets a value from the params property of a ActivatedRoute. The components looks like: ...... constructor(public userRegistration: UserRegistrationService, public userLogin: UserLoginService, public router: Router, public route: ActivatedRoute) { } ngOnInit() { this.verificationCode = new FormControl('', [Validators.required]); this.confirmationCodeForm = new FormGroup({verificationCode: this.verificationCode}); //****************************** this.sub = this.route

Angular2 how to Mock Activated Route Params subscribed

孤街醉人 提交于 2020-06-12 16:13:42
问题 I have a components that gets a value from the params property of a ActivatedRoute. The components looks like: ...... constructor(public userRegistration: UserRegistrationService, public userLogin: UserLoginService, public router: Router, public route: ActivatedRoute) { } ngOnInit() { this.verificationCode = new FormControl('', [Validators.required]); this.confirmationCodeForm = new FormGroup({verificationCode: this.verificationCode}); //****************************** this.sub = this.route

Testing: blur emulate

﹥>﹥吖頭↗ 提交于 2020-05-15 10:04:53
问题 I would like to test simple angular component with input. So an example in the bottom has little preparation for the test, and in a component should occur test function on blur, which shows log, but I have no logs in console. I tried 2 cases: getting div native element and click it and use blur() function for input native element. In angular app blur successfully occur, but it doesn't work in test. How can I fix it? @Component({ template: '<div><input [(ngModel)]="str" (blur)="testFunc($event