For RC5, need to note breaking changes for testing ngModel
See original GitHub issueThis is a note for whoever’s preparing the Changelog for RC5 😃
With the split into new forms, ngModel
is now always asynchronous when updating. This means that in tests, instead of calling ComponentFixture.detectChanges
, you’ll need to use ComponentFixture.whenStable
, which is asynchronous.
Before:
let fixture = builder.createSync(InputComp);
fixture.detectChanges();
let inputBox = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputBox.value).toEqual('Original Name');
After:
let fixture = builder.createSync(InputComp);
fixture.whenStable().then(() => {
let inputBox = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputBox.value).toEqual('Original Name');
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:12 (9 by maintainers)
Top Results From Across the Web
forms deprecated error with RC5 - angular
NOTE : docs seem to be missing or not completed yet. In RC5, new NgModule has been introduced. ... breaking changes in RC5....
Read more >Developer Guide: Migrating from Previous Versions
Minor version releases in AngularJS introduce several breaking changes that may require changes to your application's source code; for instance from 1.0 to ......
Read more >Unit testing ngModel in Angular 4
As mentioned above, this is because Angular does not automatically do change detection. Angular provides a testing utility on the fixture ...
Read more >Getting Started with Angular 2 Step by Step: 5 - Forms and ...
UPDATE (18th May 2017): This tutorial has been updated to the latest version of Angular (Angular 4). Note that the Angular team has...
Read more >Getting Started + Testing with Angular CLI and Angular 2 ...
I started creating Angular 2 applications when it was in beta ( back in March ). To keep up with Angular 2's changes,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@juliemr Is this supposed to be the final solution? To be honest this
whenStable
,autoDetectChanges
anddetectChanges
hell is super frustrating. At the moment I find myself randomly adding all that stuff + sometick
calls until at some point the test passes. 😕@choeller we’re discussing and brainstorming 😃 I get the frustration.